Validating data in php form

Rated 4.67/5 based on 692 customer reviews

Now, remember our server side will echo a JSON object with our field names and error messages?We simply handle this by adding an error class and adding a “label” with the message through j Query’s .after() function.This object contains the field names and their respective values (you can also use j Query’s .serialize() for this purpose).We make an Ajax call to our processing page – where it does the validation in our PHP code previously.Keep in mind that you will need a bit of programming know how – especially in PHP and Javascript. So when our form submits, it passes the $_POST array to this page.If you’re new to validating forms, the code below simply goes through the array and checks it against our rules for each field.Of course everything is wrapped inside our document.ready() handler, then we put a .click() for our submit button.So every time we click the submit button, we go through each field in the form and create a data object.

But the bad thing about server side validation – is you see the page refresh.Note that in our case – I’m simply checking if first name and email is empty.Of course in the real world, you will have to check for valid email and such.When in comes to validating forms, there are basically two techniques you can use: 1) Server-side validation and 2) Client-side validation.Server-side validation is when form data is submitted, server analyzes then returns the user back to the form when items are invalid.

Leave a Reply