Refresh page after form submitting

2020-02-08 04:18发布

I have a little problem. I want to reload my page after submitting a form.

<form method="post" action="">
   <textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
   <br />
   <input type="submit"  value=" Update "  id="update_button"  class="update_button"/>
</form>

标签: php html
9条回答
一夜七次
2楼-- · 2020-02-08 04:51

action attribute in <form method="post" action="action="""> should be just action=""

查看更多
对你真心纯属浪费
3楼-- · 2020-02-08 04:51

You want a form that self submits? Then you just leave the "action" parameter blank.

like:

<form method="post" action="" />

If you want to process the form with this page, then make sure that you have some mechanism in the form or session data to test whether it was properly submitted and to ensure you're not trying to process the empty form.

You might want another mechanism to decide if the form was filled out and submitted but is invalid. I usually use a hidden input field that matches a session variable to decide whether the user has clicked submit or just loaded the page for the first time. By giving a unique value each time and setting the session data to the same value, you can also avoid duplicate submissions if the user clicks submit twice.

查看更多
干净又极端
4楼-- · 2020-02-08 04:56

If you want the form to be submitted on the same page then remove the action from the form attributes.

<form method="POST" name="myform">
 <!-- Your HTML code Here -->
</form>

However, If you want to reload the page or redirect the page after submitting the form from another file then you call this function in php and it will redirect the page in 0 seconds. Also, You can use the header if you want to, just make sure you don't have any content before using the header

 function page_redirect($location)
 {
   echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';
   exit; 
 }

 // I want the page to go to google.
 // page_redirect("http://www.google.com")
查看更多
登录 后发表回答