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.Also, our users will benefit from our friendly form – and the way it gracefully tells them when they’ve missed a field and such.Let me know your thoughts and if you think this solution is a good fit for your projects.Note that in our case – I’m simply checking if first name and email is empty.
Update 4/2/2016: – The code below is not meant to be a “copy and paste” type of thing.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.Of course, if there’s no errors – the form does a hard .submit() – to the same processing page and handled accordingly.Of course, we have add our styling so our field will look like our screenshots above. Again, the styles are real basic and you probably want to do better in your own forms. We’ve combined best of both worlds: server side and client side validation in one solution (thanks to Ajax). If a field validation rule has to change – we only need to change it in one place: the server code.