我不明白为什么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)
as 的输出: 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);
}
}