Php code for validating a form

What it does is takes the data passed to the function, strips unwanted characters (extra space, tab, newline) from the beginning and end of the data using the PHP trim() function, strips any quotes escaped with slashes and passes it through htmlspecialchars().

So now instead of typing the same code for each of our input fields we simply check each $_POST variable with the check_input function and that's it.

This shows a genuine or loyal behavior of an organization towards its customers.

Here we bring up in front of you the PHP contact form with validation feature.

Very first we have to create a form in html setting action “#” and method “POST” with some fields, when a user clicks on submit button all the data starts travel in URL but it will be hidden, as we set method = “POST”.

php code for validating a form-26php code for validating a form-62

Such code can now do no harm and is safe to be displayed on a page or inside an e-mail. if quotes are escaped with a slash \ let's remove that.

In this tutorial you'll learn how to sanitize and validate form data using PHP filters.

As you have seen in the previous tutorial, the process of capturing and displaying the submitted form data is quite simple.

There are two types of validation are available in PHP.

It is very essential to have the input to your form validated before taking the form submission data for further processing.


Leave a Reply