Php validating text input
However, because the variables are not displayed in the URL, it is not possible to bookmark the page.
To show the values in the input fields after the user hits the submit button, we add a little PHP script inside the value attribute of the following input fields: name, email, and website.
Let's say we save this code in a file called "test.html".
When submitted data is sent to the "myform.php" file using POST HTTP method. You need to validate submitted data to protect your script (and thus your website and server) from malicious code.
To validate email address, there is a special function available in PHP which we can use to validate email addresses. Validating a form in PHP depends on your requirements too.
In the code above we are checking whether the user has entered name value in the form or not, similarly you can put a check on all the mandatory form fields.All variables passed to the current script via the HTTP POST method are stored in associative array $_POST. Let's say you display all data submitted with the form in a HTML file (like a guestbook does for example). Failure to properly validate input data is the main reason for most vulnerabilities and exploits in PHP scripts.