Validating a web form in php

Rated 3.92/5 based on 554 customer reviews

Today is my first day working with php and I finally figured out how to get my page to post back to itself (I'd had the page as .html, instead of .php), but now I'm having trouble figuring out how to take the data to a new page after the form has been validated. Just want to [email protected], Javascript is nice feature to have, but it is only optional. This should go right under the rest of my if/else processing, right?I've been working on it for quite a while and I'm fried. So above, you'll see that the form posts back to itself so it can validate. Now, considering all things are valid, how do I post to another script (action="other Action.php", maybe? PHP is MUST because it is your last defense against awful data. Is this a more efficient way to do things because a new variable doesn't have to be instantiated?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.On the other hand, users will have to fill in the information without getting a response until they submit the form. Validation in this context refers to validating rules such as username availability.You can read more about validation with Ajax in this excellent tutorial on j Query For Designers.

Most of cases we will use the * symbol for required field.

(granted the performance gain will be negligible) Are there other benefits over @Drixson's answer?

@vincent, Drixson's answer and my answer is basically using the same concept with a slightly different approach.

Each field in the form can have zero, one or more validations.

For example, the input should not be empty, should be less than 25 chars, should be alpha-numeric, etc You can associate a set of validation descriptors for each input field in the form.

Leave a Reply