简体   繁体   中英

How can I avoid taking users to www.website.com/filename.php after they submit a form?

I was wondering if anyone knows how to automatically refresh a webpage after clicking on a form submit button rather than being taken to a .php page?

Here's my html:

<p>
<form action='action.php' method='post'>
<textarea name='message' rows='3' cols='30'>
</textarea><br><br>
<input type='SUBMIT' value='Submit' />  
</p>

Here's my php:

<?php 
$message = $_POST['message']; 
mail("name@website.com","", $message)
?>

Any help much appreciated,

Guy Brown

If you want you can do it in same file where form is located like this (if form is located in action.php or change action.php to php self as suggested):

<p>
  <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
    <textarea name='message' rows='3' cols='30'>
    </textarea><br><br>
    <input type='SUBMIT' value='Submit' />  
  </form>
</p>
<?php 
if(isset($_POST['message'])) {
  $message = $_POST['message']; 
  mail("name@website.com","", $message)
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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