dqk77945 2014-04-25 13:19
浏览 31
已采纳

提交表单后,为什么select控件中已检查元素的值不会出现在$ _POST数组中? [重复]

This question already has an answer here:

I've following HTML code:

<form action="rebates.php" role="form" method="post">
<select id="example28" multiple="multiple" name="applicable_states">
    <option value=""  selected='selected'>Select Unit</option>
    <option value="1" >Alabama</option>
    <option value="2" >Alaska</option>
    <option value="3" >Arizona</option>
    <option value="4" >Arkansas</option>
    <option value="5" >California</option>
 </select>
<button type="submit" class="btn btn-primary">Preview</button>
</form>

The JQuery code for select control is as follows:

/*jQuery Code*/
 $(document).ready(function() {
    window.prettyPrint() && prettyPrint();
     $('#example28').multiselect({
         includeSelectAllOption: true,
         maxHeight: 150
     });
 });

I've used Bootstrap's js and css (Multiselect and Prettify) to achieve this. My issue is I'm not getting the checked elements' values after submission of form in $_POST array oe rebates.php. Can someone please help me in this regard? Thanks in advance. When I check some values from the select control and submit the form I'm getting the $_POST array as follows:

Array
(
 [applicable_states] => 11
 [multiselect] => 11
)

Why this is happening? The code in rebates.php is as follows:

<?php
print_r($_POST); die;
?>
</div>
  • 写回答

1条回答 默认 最新

  • dppb79372 2014-04-25 13:55
    关注

    PHP needs to know it's an array. So you need to change the name of the select.

    name="applicable_states[]"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥100 单片机hardfaulr
  • ¥20 手机截图相片分辨率降低一半
  • ¥50 求一段sql语句,遇到小难题了,可以50米解决
  • ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
  • ¥15 虚拟机检测,可以是封装好的DLL,可付费