javascript - 如何在引导模式中提交表单时重定向到同一页面?
问题描述
我有一个带有表单的引导模式,它是从我父主页中的链接调用的:
<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">×</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'”,但它实际上并没有提交表单,它只是关闭了模式。
解决方案
推荐阅读
- .htaccess - 将不带通配符的子文件夹重定向到主 URL
- php - 操作 Drupal 8 currentUser 角色数组
- laravel - Laravel:如何制作一个独立的功能?
- ffmpeg - 由于 32 位支持,无法将 libopenh264-2.0.0-android.so 用于我的 android 应用程序
- php - 如何根据用户引用加载脚本
- ios - 使 UIBezierPath 可选择并更改其颜色
- javascript - 字符串操作jsx
- spring-boot - Docker:运行 docker logs 时如何打印 jvm 内存信息
- c# - 通过断言状态码返回单元测试 .net 项目
- docker - 如何从另一个 docker 容器中调用位于 docker 容器上的 ansible playbook