Clear the form field after successful submission of php form

后端 未结 12 1726
春和景丽
春和景丽 2020-12-16 06:10

I am making a simple Form the problem i am facing is when i submit the form values still remains in the field. and I want to clear it after SUCCESSFUL submission. Please hel

12条回答
  •  春和景丽
    2020-12-16 06:57

    They remain in the fields because you are explicitly telling PHP to fill the form with the submitted data.

    
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HERE
    

    Just remove this, or if you want a condition to not do so make a if statement to that echo or just cleanup the $_POST fields.

    $_POST = array(); // lets pretend nothing was posted
    

    Or, if successful, redirect the user to another page:

    header("Location: success.html");
    exit; // Location header is set, pointless to send HTML, stop the script
    

    Which by the way is the prefered method. If you keep the user in a page that was reached through a POST method, if he refreshes the page the form will be submitted again.

提交回复
热议问题