-1

我不明白为什么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);




    }


}
4

2 回答 2

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" }
于 2012-10-22T07:49:59.027 回答
0

尝试改用 $_REQUEST 资源。很明显,有些东西正在破坏您的 $_POST,但我无法在您提供的代码中发现它。此外,当它是一个超全局变量时,我看不到将 $_POST 数组作为参数传递给函数的目的。

于 2012-10-22T08:01:25.683 回答