单击“提交”后重定向页面

时间:2016-11-30 02:51:02

标签: php forms contact

我想知道如何点击我的提交按钮并且URL没有改变。现在,当我点击它时,它只是向我发送了操作页面。

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;		
?>

我想知道是否有人可以帮助我这样做它停留在页面而不是重定向。

1 个答案:

答案 0 :(得分:1)

您应该使用与操作页面相同的页面,如:

<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'])  
...
...
?>
相关问题