提交的启动模式对话框未显示id值


Bootstrap Modal Dialog on submitted not displaying id value

我在使用引导程序的模式对话框时遇到问题。这是我的代码:我希望正确显示id按钮,不仅打开模式对话框,而且它不起作用。它总是显示为空白。但是,如果我将类型"button"更改为"submit",则获取正确的id,但不显示模式对话框。怎么了??谢谢大家的关注。这是我的代码:

<table class="table table-bordered">
    <tr>
      <td> <input type="checkbox" id="box1" name="box1"> <b>Seleziona tutto</b></td>
      <td> <b>Pratica</b> </td>
      <td> <b>Filiale</b> </td>
    </tr>
    <?php
      $query = mysql_query("SELECT * from plprat ") ;
      while ($row = mysql_fetch_array($query)) {
        echo "<tr>";
        echo "<td><input type='checkbox' class='box' name='box[]' value=".$row['id']."></td>";
        echo "<td>" . $row['pratica'] . "</td>";
        echo "<td>" . $row['filiale'] . "</td>";
        //echo "<td><form method='POST' action='Cancella.php'><button type='submit' name='Cancella' class='btn btn-default' value=".$row['id'].">Cancella</button></form></td>";
        echo "<td><form method='GET'><button type='button' id='modifica' name='modifica' data-toggle='modal' data-target='#myModal' class='btn btn-default' value=".$row['id'].">Modifica</button></form></td>";
        echo "</tr>";
      }
    ?>
  </table>
<!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">Modifica dati</h4>
        </div>
          <div class="modal-body">
            <?php
              $id = $_GET['modifica'];
              echo $id;
              $query = mysql_query("SELECT * FROM plprat WHERE id = $id");
              while ($row = mysql_fetch_array($query)) {
            ?>
                <b>Pratica</b> <input type="text" id="pratica" name="pratica" value="<?php echo $row['pratica']; ?>">
                <b>Filiale</b> <input type="text" id="filiale" name="filiale" value="<?php echo $row['filiale']; ?>">
            <?php
              }
            ?>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Chiudi</button>
            <button type="submit" id="salva" name="salva" class="btn btn-primary">Modifica</button>
          </div>
      </div>
    </div>
  </div>

这个行为就是您编码的,让我来解释一下发生了什么。

为什么不起作用

你把模态按钮放在一个窗体中,但你没有在模态中使用窗体。因此,如果你将模态按钮更改为提交,它会在你点击它时提交,但你的模态没有打开,甚至。。。该页面已在提交表单。
您的模态不包含任何<form>,因此"保存"按钮不在<form>中,并且永远不会提交任何内容。

如何解决

首先删除包装您的模态按钮的form标记,这是没有用的。将表单标记直接作为.modal内容的子项,并将您需要的输入数据放入其中。

我能为您提供更多帮助吗

  • 在PHP中,只使用一个echo来显示多行毫无理由地使用过多回声的速度较慢
  • 更喜欢用英语编码,避免使用自己的语言(如果显然不是英语),你会让它更容易被其他人访问,也会让它更有价值
  • 动态填充模态
  • 您可能需要:将JSON数据转换为Bootstrap模式
  • 为您的DBMS使用PHP框架或至少一个库