簡體   English   中英

單擊提交后重定向頁面

[英]Redirect Page after clicking Submit

我想知道如何在我單擊“提交”按鈕且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; ?> 

我想知道是否有人可以幫助我,所以它停留在頁面上而不是重定向。

您應該使用與操作頁面相同的頁面,例如:

<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