简体   繁体   English

单击提交后重定向页面

[英]Redirect Page after clicking Submit

I am wondering how to make it where I click my submit button and the URL doesnt change. 我想知道如何在我单击“提交”按钮且URL不变的情况下进行设置。 Right now when I click it it just sends me the the action page. 现在,当我单击它时,它将向我发送操作页面。

The PHP Code is PHP代码是

 <?php // Check for empty fields if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; } $name = strip_tags(htmlspecialchars($_POST['name'])); $email_address = strip_tags(htmlspecialchars($_POST['email'])); $message = strip_tags(htmlspecialchars($_POST['message'])); // Create the email and send the message $to = 'me@lolnick.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to. $email_subject = "Website Contact Form: $name"; $email_body = "You have received a new message from your website contact form.\\n\\n"."Here are the details:\\n\\nName: $name\\n\\nEmail: $email_address\\n\\nMessage:\\n$message"; $headers = "From: noreply@yourdomain.com\\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com. $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); return true; ?> 

I was wondering If someone can help me make it so It stays at the page instead of redirecting. 我想知道是否有人可以帮助我,所以它停留在页面上而不是重定向。

You should use the same page as the action page like: 您应该使用与操作页面相同的页面,例如:

<form action = 'samepage.php'>
  <input type='text' name = 'name'>
  <input type='text' name = 'email'>
  <input type='text' name = 'message'>
  <button type="submit">Submit</button>
</form>
<?php
// Check for empty fields
if(empty($_POST['name'])  
...
...
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM