PHP表单提交和重定向
PHP form submit and redirect
所以我有一个模式表单,我想在其中获取输入的字段,并将其发送到我想要的电子邮件地址,然后将其重定向到某个网页/下载页面我已经用PHP完成了这项工作,但我想使用客户端重定向它,只需使用PHP邮件进行字段解析即可获得电子邮件,我必须创建大量的PHP表单才能做到这一点,因为重定向url在许多情况下是不同的。
这是PHP
$to = "some@email.com";
$subject = "Contact Page";
$headers = "From: Contact Page";
$forward = 1;
$location = "somelocation";
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.'n'n";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "'n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "'n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
print("You will be redirected to your download link shortly";)
header ("Location:$location");
}
else {
include("index.html");
}
现在html
<!-- Modal content -->
<div class="modal-content">
<span class="close">x</span>
<form method="POST" onsubmit="myFunction()" action="form2.php">
<label for='name'>Name: </label>
<input type="text" name="name" >
<label for='email'>Email: </label>
<input type="text" name="email" >
<input type="submit" id="submit" value="Submit" name="submit">
<script>
function myFunction() {
alert("form Submitted Successfully you will be redirected shortly");
}
</script>
您可以使用JavaScript的window.location.assign()函数重定向到另一个页面。请尝试以下操作。
<script>
function myFunction() {
alert("form Submitted Successfully you will be redirected shortly");
window.location.assign("http://urlOfThePageYouWantToRedirectTo");
}
</script>
您可以将这段代码放在form2.php文件中。
请记住,您需要form2.php文件中的HTML代码才能正常工作
请确保将其放置在head标签下方。
<meta http-equiv="refresh" content="0; url=http://YourRedirectLink.com/" />
如果要延迟重定向(以秒为单位),请更改content属性的值。
为什么不通过ajax提交表单,并在成功响应时重定向表单呢。
<script>
function myFunction() {
//ajax code
//on success
alert("form Submitted Successfully you will be redirected shortly");
//Redirect on url you want
window.location.href= "write_your_url_here";
}
</script>
相关文章:
- 如何根据所选选项值重定向表单操作
- PHP表单提交和重定向
- 表单提交时重定向页面
- 根据答案重定向表单
- ajax表单提交后从客户端重定向
- 模拟隐藏表单提交&使用JavaScript重定向以实现安全支付
- 高级表单提交-单选、复选框和重定向
- 如何使用单击此处提交重定向表单
- Safari在重定向/表单提交时暂停所有动画
- 防止在没有ajax的情况下提交后重定向表单
- 如何重置表单提交事件的 event.preventDefault()
- 重定向表单失败
- 提交后重定向表单
- 在提交时使用JavaScript重定向表单插件
- JavaScript重定向表单提交
- 我需要提交表单,并在一个花哨的框中重定向表单提交的父页面
- 如何使用jquery提交和重定向表单?
- 使用下拉字段中的值重定向表单提交上的页面
- 重定向表单用户提交时,基于无线电选择仅
- 我试图在表单提交到一个新页面后,根据用户选择的多个选项(Javascript.html)重定向表单