我不理解为什么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);
}
}
答案 0 :(得分:0)
这对我来说很好用:
<?php
if(isset($_POST['forms'])){
$forms=$_POST['forms'];
var_dump($forms);
}
?>
<form method="post" name="test" action="">
<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>
<input type="submit" name="test" value="go"/>
</form>
输出
array(2) { [0]=> string(17) "ArticlesOrderForm" [1]=> string(17) "PressReleasesForm" }
答案 1 :(得分:0)
尝试使用$ _REQUEST资源。显然有些东西会破坏你的$ _POST,但我无法在你提供的代码中发现它。另外,当它是超全局时,我没有看到将$ _POST数组作为参数传递给函数的目的。