Iam不理解为什么var_dump()
将数组视为字符串。请您检查下面的代码出了什么问题:为什么var_dump显示为数组的字符串?
<div id="chooseForm">
<input type="checkbox" name="forms[]" id="forms" value="ArticlesOrderForm"> <b>Articles Order Form </b><br>
<input type="checkbox" name="forms[]" id="forms" value="PressReleasesForm"> <b> Press Releases Form </b><br>
</div>
if(isset($_POST['forms']) && $_POST['forms']!=''){
$table = $wpdb->prefix . "eshop_orders";
$forms=$_POST['forms'];
var_dump($forms);
}
我得到输出var_dump($forms)
为:string(5) "Array"
为什么它不考虑作为一个数组?我会很高兴,如果有人可以理清这个问题..
编辑:
// Add an additional field to the checkout within a new fieldset
add_filter('eshopaddtocheckout','eshop_extras_checkout');
function eshop_extras_checkout($echo){
$echo .= ' <script>
jQuery(function($) {
$(".formGroup").hide();
$("#chooseForm input:checkbox").on("change", function() {
if($(this).is(":checked")) {
$("#" + $(this).val()).show();
}
else {
$("#" + $(this).val()).hide();
}
});
});
</script>';
$echo .= '<fieldset class="eshop eshop_extra">' . "\n";
$echo .= '<legend>Select the Approriate Form</legend>' . "\n";
$echo .= ' <div id="chooseForm">
<input type="checkbox" name="forms[]" value="ArticlesOrderForm"> <b>Articles Order Form </b><br>
<input type="checkbox" name="forms[]" value="PressReleasesForm"> <b> Press Releases Form </b><br>
</div>
<div id="ArticlesOrderForm" class="formGroup">
<legend>Articles Order Form</legend>
<label for="kwd1">Art-Keywords1</label><input class="short" type="text" name="kwd1" value="" id="kwd1" maxlength="20" size="20" > <br>
</div>
<div id="PressReleasesForm" class="formGroup">
<legend>Press Releases Form</legend>
<label for="kwd2">PRKeywords2</label><input class="short" type="text" name="kwd2" value="" id="kwd2" maxlength="20" size="20"> <br>
</div>';
$echo .= '<fieldset class="eshop eshop_extra">' . "\n";
$echo .= '<legend>Extras</legend>' . "\n";
$echo .= '<label for="eshop_extra">'.__('Extra Field','eshop').' <span class="reqd">*</span><br />
<input class="short" type="text" name="eshop_extra" value="" id="eshop_extra" maxlength="20" size="20" /></label><br />';
$echo .= '</fieldset>' . "\n";
return $echo;
}
// Saves extra field data in db
add_action('eshoporderhandle','eshop_extras_orderhandle',1,2);
function eshop_extras_orderhandle($_POST,$checkid){
//we need to save the data
global $wpdb;
if(isset($_POST['eshop_extra']) && $_POST['eshop_extra']!=''){
$table = $wpdb->prefix . "eshop_orders";
$eshop_extra=$wpdb->escape($_POST['eshop_extra']);
$query1=$wpdb->query("UPDATE $table SET eshop_extra='$eshop_extra' where checkid='$checkid' limit 1");
}
if(isset($_POST['kwd1']) && $_POST['kwd1']!=''){
$table = $wpdb->prefix . "eshop_orders";
$kwd1=$wpdb->escape($_POST['kwd1']);
$query1=$wpdb->query("UPDATE $table SET kwd1='$kwd1' where checkid='$checkid' limit 1");
}
if(isset($_POST['kwd2']) && $_POST['kwd2']!=''){
$table = $wpdb->prefix . "eshop_orders";
$kwd2=$wpdb->escape($_POST['kwd2']);
$query1=$wpdb->query("UPDATE $table SET kwd2='$kwd2' where checkid='$checkid' limit 1");
}
if(isset($_POST['forms']) && $_POST['forms']!=''){
$table = $wpdb->prefix . "eshop_orders";
$forms=$_POST['forms'];
var_dump($_POST);
}
}
就像一个旁注:你在''字段中使用了相同的'id'。在整个文档中,Ids必须是唯一的(因此名称*标识符*)! – Sirko
你在使用cURL吗? [这](http://www.icreatestuff.co.uk/index.php/blog/article/php-post-converting-array-to-string-array)家伙有类似的问题。 –
从发布的代码中不可能判断出什么问题;如果我将你的代码包装到合适的HTML和PHP代码中,它就可以工作。 –