Jump to content
Larry Ullman's Book Forums

Recommended Posts

First off, what a well written technical book! Thanks Larry.


I'm working on a project that currently uses JavaScript validation. The page will have PHP functionality later, but after reading chapter 6's validation examples, I got to thinking . . .


Can I have slicker AJAX style same page validation using PHP? This would put the error messages in the same page after form field completion but before submission.


I saw an example elsewhere that essentially points the action to the same page, but it used a lot of "include" scripting. The validation scripting in the book is so simple, yet the JavaScript currently being used in my project seems so unnecessarily clunky.


So, in short, what is the easiest way to augment the validation example in the book for same page validation? Would it be more efficient than AJAX validation?

Link to post
Share on other sites

Thanks for the nice words on the book. Much appreciated. As for your question, the problem with JavaScript validation is that it cannot be relied upon, particularly as a security measure. It's too easy for someone to disable JavaScript or be using a device that doesn't support it. What you really want to do is implement the complete PHP functionality first, and then add a layer of JavaScript validation on top of that. The JavaScript validation would essentially highjack the form submission and only allow the submission to go through if the data passes the JavaScript validation.


I'm writing a JavaScript book now and stress this approach (called "progressive enhancement") repeatedly.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...