Validating a form with php

Rated 4.58/5 based on 530 customer reviews

The user can disable Javascript on their server or even auto-bots might try to submit your form as well.

The server side form validations help keeping the form submission data consistent.

The “validation descriptor” is a string specifying the type of validation to be performed.

For example, “req” means required, “alpha” means allow only alphabetic characters and so on.

What is the the most convenient way, the "best" way for validate a form with PHP? Because, more special characters can use the person when compile the password input during the registration, more secure is his account.

I don't want languages like Javascript for validate my form, I want to know the best approach for do a form validation using only PHP, the more cleanly way to do it. If you're validating data on server side, And your validation does not require application business logic (i.e you're not checking to see if the user has enough credit in his account), You should validate in the controller.

You could do it a little more elegant using OOP, but I think for the code you posted above the example should do.

Moreover, since you are doing the same or similar validation for most of the forms that you make, just too much of duplicate effort is spent on form validations.

Note: You can make web forms quickly with Simfatic Forms.

Client-side form validations help in giving immediate feedback to the user.

It is also required to add server side form validation in your form processing script.

Leave a Reply