Form validation with php

Almost Every website has form whether it is login form, registration form, subscribe form etc. It is the basic requirement that every form should be validated. If you are just a beginner then now you can ask me that what form validation is.

Form validation means that when you submit the form then php script (or any script) will check all the data that you submitted. If your submitted data is correct then you can proceed next and if not then you will see the errors. For example, If you submit wrong email in the email field then it will show you error that your email is wrong.

Wrong Email: Suraj@

Correct Email: Surajkumardotin@gmail.com

Here I am going to explain form validation with php  with very easy way. For the better understanding I have created an example in which I am validation form and if all the submitted data will be ok then it will show a success message else it will show error messages. Following is the example of form.

validation form

In this form, you can see that i have created a asterisk sign which means that those fields are compulsory. i have created this form with the help of bootstrap and in this form i am using Ubuntu font. Following is the source code of this form.

In this script i have created an empty field validation, email validation and numeric field validation. Validation depends on your requirements like you can also check minimum and maximum number of character that user should add in the form. This is just the basic example so that you can take a idea from this.

Now following is the code which implements form validation:

If you are beginner then you have opportunity to learn lots of things like how you work with array, loops and if conditions.

 

Full Source Code: