首页 > 解决方案 > 如何在引导模式中提交表单时重定向到同一页面?

问题描述

我有一个带有表单的引导模式,它是从我父主页中的链接调用的:

 <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Contact</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      <form method="post" action="student.php"  target="_parent">
    <div class="form-group row">
    <div class="col">
      <input type="text" class="form-control" placeholder="Name" name = "name">
    </div>
    <div class="col">
    <label class="mr-sm-2 sr-only" for="inlineFormCustomSelect">Profession</label>
      <select class="custom-select mr-sm-2" id="inlineFormCustomSelect" name="profession">
        <option selected>Choose...</option>
        <option value="1">Student</option>
        <option value="2">Parent</option>
        <option value="3">Other</option>
      </select>
    </div>
  </div>
  <div class="form-group">
      <input type="text" class="form-control" placeholder="e-mail" name = "email">
    </div>
  <div class="form-group">
  <label class="mr-sm-2 sr-only" for="inlineFormCustomSelect">Type</label>
      <select class="custom-select mr-sm-2" id="inlineFormCustomSelect" name="type">
        <option selected value="1">Feedback</option>
        <option value="2">Grievance</option>
        <option value="3">Admission</option>
        <option value="4">Other</option>
      </select>
      </div>
     <div class="form-group">
    <label for="exampleFormControlTextarea1">Write..</label>
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="3" name="message"></textarea>
  </div>
</form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Send Message</button>
      </div>
    </div>
  </div>
</div>

我的父页面中的 PHP 代码用于处理我的模态表单的数据。

<?php 

    if(isset($_POST["submit"]))
    {
        $email = $_POST["email"];
        $name = $_POST['name'];
        $message = $_POST["message"];
        $type = $_POST["type"];
        $profession = $_POST["profession"];
        $message = wordwrap($message,70);
        $headers = "From:".$email;
        $subject = "Message by".$name." ".$profession."of type".$type;
        mail("yashboura303@gmail.com", $subject, $message, $headers);

        echo "Your mail has been sent successfuly ! Thank you for your feedback";
    }
?>

现在我想在提交我的模态表单后返回 home.php,以便我可以使用 mail() 函数发送邮件。我怎样才能做到这一点?我显然在表单中使用了“action=home.php”,该表单不起作用,并且在提交按钮标签中使用了“data-dismiss='modal'”,但它实际上并没有提交表单,它只是关闭了模式。

标签: javascriptphphtmltwitter-bootstrap

解决方案


推荐阅读