drap5081683 2016-12-01 21:27
浏览 152

Bootstrap-select不提交选择

I have this form:

<script src="./bootstrap-select/js/bootstrap-select.js"></script>
<form action="rec.php" name="submit" method="post">
    <select name="all[]" class="form-control">
        <?php
        for($i = 0; $i < 10; $i++) {
        ?>
        <option value="details<?=$i?>"><?=$i?></option>
        <?php } ?>
    </select>
    <?php
    for($i = 0; $i < 10; $i++) {
    ?>
    <input type = "hidden" name="infos[]" value="<?=$i?>">
    <?php } ?>
    <input type="submit" vale="submit" name="submitit">
</form>

rec.php:

<?php
print_r($_REQUEST);
?>

When I submit the form, I get only Arrays of infos[] and nothing about all[]. When I remove bootstrap-select and resubmit the form, I get all the results.

How to fix bootstrap-select in order to solve my problem?

I am using Bootstrap-select v1.10.0.

  • 写回答

1条回答 默认 最新

  • dpz1983 2016-12-01 22:06
    关注

    I'd have left a comment but it doesn't allow me to post pretty output. I replicated your code

    index.php

    <script src="bootstrap-select/js/bootstrap-select.js"></script>
    <form action="rec.php" name="submit">
        <select  name="all[]" class="form-control">
            <?php
            for($i = 0; $i < 10; $i++) {
                ?>
                <option value="details<?=$i?>"><?=$i?></option>
            <?php } ?>
        </select>
        <?php
        for($i = 0; $i < 10; $i++) {
            ?>
            <input type = "hidden" name="infos[]" value="<?=$i?>">
        <?php } ?>
        <input type="submit" value="submit" name="submitit">
    </form>
    

    rec.php

    <?php
    echo "<pre>";
    var_dump($_REQUEST);
    echo "</pre>";
    

    It looks like you're trying to implement a multi select, however it's clear to me that the select i'm seeing is just a regular select, and a regular select can only have one value

    This is the output that i see:

    array(4) {
      ["all"]=>
      array(1) {
        [0]=>
        string(8) "details1"
      }
      ["infos"]=>
      array(10) {
        [0]=>
        string(1) "0"
        [1]=>
        string(1) "1"
        [2]=>
        string(1) "2"
        [3]=>
        string(1) "3"
        [4]=>
        string(1) "4"
        [5]=>
        string(1) "5"
        [6]=>
        string(1) "6"
        [7]=>
        string(1) "7"
        [8]=>
        string(1) "8"
        [9]=>
        string(1) "9"
      }
      ["submitit"]=>
      string(6) "submit"
      ["Phpstorm-2043c6b"]=>
      string(36) "........." <- ignore this
    }
    

    Can you explain to me what about that output is different than what you expected?

    Note: The documentation you linked to suggested the class on the select should be: selectpicker

    And you need this line:

    <script>
        $('.selectpicker').selectpicker();
    </script>
    

    However this leads to the error:

    • Uncaught ReferenceError: jQuery is not defined(…)

    • Uncaught ReferenceError: $ is not defined(…)

    You need to at least include Jquery to make the multi select work. (I haven't tested this)

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料