Ask Your Question

What are the recommended techniques for handling forms in PHP, including resubmission and the use of the back button?

asked 2022-09-09 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-30 19:00:00 +0000

ladyg gravatar image
  1. Use the POST method: When creating HTML forms, it's important to use the POST method rather than GET. This helps prevent resubmission of forms and adds extra security to your website.

  2. Use form validation: Form validation is important to ensure that the data entered into the form is correct and complete. It helps prevent errors and fraudulent submissions.

  3. Use unique tokens: To prevent resubmission of forms, it is recommended to generate unique tokens for each form submission. This can be done by creating a unique identifier for each form that is then checked on form submission.

  4. Use sessions: Sessions can be used to store form data and validate tokens. This helps keep track of user data and prevents submission of forms that have already been submitted.

  5. Use redirection: When a form is submitted, it is recommended to redirect the user to a confirmation page rather than simply reloading the current page. This helps prevent resubmission of the form and provides a better user experience.

  6. Add message alerts: Whenever there is an error in form submission or an incomplete field, the PHP script can be set to return error messages. This allows the user to receive feedback and complete the form quickly.

  7. Pre-fill form data: If a user returns to a form after submitting it, it is recommended to pre-fill the form data to save them time. This can be done by saving the user data in sessions or using cookies.

  8. Use the history API: The history API can be used to control the back button of the browser. This way, when the user clicks the back button, the form data is not lost and can be re-submitted.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2022-09-09 11:00:00 +0000

Seen: 15 times

Last updated: Nov 30 '21