无法显示 if 条件之后的模态



我有一个关于引导模式的问题:我有一个输入框和一个按钮,在输入框中,用户应该输入他们的代码,然后单击检查按钮:

<form class="form-inline" action="" method="post">
  <div class="form-group">
    <input type="text" class="form-control input-sm input-inverse" name="appcode" required="" data-form-field="appcode" placeholder="Insert Your Code"></div>
  <div class="buttons-wrap">
    <button name="Xcheck" class="btn btn-secondary display-4 " type="submit" role="button" data-toggle="modal" data-target="#modalID">Check</button>
  </div>
</form>

单击按钮时,它将在同一页面中运行PHP代码,并检查插入的代码是否存在于数据库中。

这是 php 代码:

<?php
  $con= mysqli_connect("localhost", "root", "");
  mysqli_select_db($con, "cobathesis");
  if (isset($_POST['Xcheck'])){
    $appcode= $_POST['appcode'];
    $check=mysqli_query($con,"select * from applicantdata where appcode='$appcode'");
    $checkrows=mysqli_num_rows($check);
    if($checkrows>0) {
        // the modal should be loaded here
    }else{
        echo "<script>alert('You Inserted either the wrong Code or the Code is unregistered'); location.href='';</script>";
        }
  }
?>

是否可以使用相同的按钮(检查按钮(来发布值并同时加载模态?

感谢您的回复。

你可以使用类似的东西

$('#myForm').on('submit', function(e){
  $('#myModal').modal('show');
  e.preventDefault();
});

Hana Piers 的 CodePen

最新更新