I have a basic html form with input and select form fields. How do I prevent the form from deleting all of the values during the validation process? This is assuming the form returns validation errors.
The form is not deleting anything .. input is not automatically restored in a form on submission since you are redirecting to the same page. You need to store the values on a persistence layer (_SESSION
or a DB) and write them back out to the form once you have initially acquired them.
The form won't delete values. When the form is submitted, the browser will make an HTTP request to the server. The server will respond with (probably) an HTML document.
If that HTML document is a duplicate of the original form with some added error messages, then that is what the browser will display.
If you want the data to be preserved, then the HTML document you generate in response to the form submission needs to include the data (mostly via the value
attribute which applies to most form controls).