使用引导模式形式的ADD不起作用


ADD using Bootstrap Modal form is not working

我想使用模式表单来填充我的当前表,但它不起作用。我只是需要一些帮助,我可能错过了什么。谢谢

这是我的按钮代码:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addModal" href="add_dept.php">+ Add Department</button>

以下是我在文件底部的代码,用于显示模式内容:

<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <div class="modal-content">
    </div>
</div>

这是我的add_dept.php代码:

<?php include("../includes/config.php");
$reqErr = "";
if($_SERVER['REQUEST_METHOD'] == "POST") {
  if(!empty($_POST['dept_name']) && !empty($_POST['dept_code'])) {
    $dept_name = $_POST['dept_name'];
    $dept_code = $_POST['dept_code'];
    $query_addDept = "INSERT INTO department(dept_name,dept_code) VALUES('$dept_name','$dept_code')";
    if(mysqli_query($con,$query_addDept)) {
        $reqErr = '<div class="alert alert-success" id="myAlert">
              <a href="" class="close"> &nbsp;  <i class="fa fa-times"></i></a>
            <i class="fa fa-check-circle"></i> Department added</div>';
            mysqli_close($con);
    }
    else {
      $reqErr = '<div class="alert alert-danger" id="myAlert">
            <a href="" class="close"> &nbsp;  <i class="fa fa-times"></i></a>
          <i class="fa fa-exclamation-circle"></i> Failed to add Department</div>';
    }
  }
}
?>
<?php echo $reqErr; ?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Add Department</h4>
</div>
<div class="modal-body">
  <form method="POST" class="form" id="add-department" role="form">
  <div class="form-group">
    <input type="text" class="form-control" id="dept_name" name="dept_name" placeholder="Department Name" />
    <span class="help-block"></span>
  </div>
  <div class="form-group">
    <input type="text" class="form-control" id="dept_code" name="dept_code" placeholder="Department Code" />
    <span class="help-block"></span>
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <input type="submit" id="submit_btn" class="btn btn-primary" />
  </div>
  </form>
</div>
  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addModal" href="add_dept.php">+ Add Department</button>

删除href="

 <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
              <?php require_once('add_dept.php'); ?>
         </div>
     </div>
</div>

添加最后一个关闭的div

data-target="#addModal" href="add_dept.php"

你的问题就在这里。

您不能将按钮设置为模型触发器和创建页面的链接。

您可以触发模态,在再次单击模态后,重定向到您的add_dept.php页面,或者只在单击时重定向,而不使用模态。