AJAX and PHP: Building Responsive Web Applications
www.PACKTPUB.com FREE ONLINE EDITION: Read full chapters online, download free samples from the book and more...
Book Contents Index > Chapter 4

Introduction
1: AJAX and the Future Of Web Applications
2: Client-Side Techniques with Smarter JavaScript
3: Server-Side Techniques with PHP and MySQL
4: AJAX Form Validation
5: AJAX Chat & JSON
6: AJAX Suggest and Autocomplete
7: SVG (Scalable Vector Graphics)
8: AJAX Grid  
9: AJAX RSS Reader
10: AJAX Drag and Drop
Appendix A: Configuring Your Working Environment
Appendix B: Using Smarter Tools to Write Better Code
Appendix C: Advanced XML

Index

Free Chapters:
Chapter 1: AJAX and the Future Of Web Applications [0.5 MB PDF]
Chapter 5: AJAX Chat [1 MB PDF]

Free eBook:
AJAX Whiteboard mini-book

Code Download

Contact us

Chapter 4: AJAX Form Validation
Validating input data is an essential requirement for quality and secure software applications. In the case of web applications, validation is an even more sensitive area, because your application is widely reachable by many users with varying skill sets and intentions. Validation is not something to play with, because invalid data has the potential to harm the application's functionality, and even corrupt the application's most sensitive area: the database.

Input data validation means checking whether the data entered by the user complies with previously defined rules, which are established according to the business rules of your application. For example, if you require dates to be entered in the YYYY-MM-DD format, then a date of "February 28" would be considered invalid. E-mail addresses and phone numbers are other examples of data that should be checked against valid formats.
 
Carefully define the input data validation rules in the software requirements document of the application you're developing, and then use them consistently to validate your data! Historically, web form validation was implemented mostly at the server-side, after the form was submitted. In some cases, there was also some JavaScript code on the client that performed simple validation such as checking whether the e-mail address was valid, or if a user name had been entered.

The problems encountered with traditional web form validation techniques are:
  • Server-side form validation meets the limits of the HTTP protocol, which is a stateless protocol. After submitting a page containing invalid data an empty form reloads prompting the user to fill the form all over again. To deal with this issue a special code needs to be written.

  • When submitting the page, the user needs to wait for a full page reload. For every mistake that is done when filling the form, a new page reload happens.
    In this chapter, we will create a form-validation application that implements the good old traditional techniques and adds an AJAX flavor, thereby making the form more user-friendly and responsive.

Even if you implement AJAX validation, server-side validation is mandatory, because the server is the last line of defense against invalid data. The JavaScript code that gets to the client can not only be disabled permanently from the browser's settings but also can be easily modified or bypassed.

The code in this chapter can be verified online at http://cristian.nexcess.net/ajax/validate

 

Chapter 4: AJAX Form Validation
  • Implementing AJAX Form Validation
  • Summary

   

 

Paperback 250 pages
Released: February 2005
ISBN: 1847192825
ISBN 13:
978-1-904811-82-4

eBook Version Also Available
Buy the book & eBook together and get 80% off the eBook

     

 




View the book details
on PacktPub.com

 


 
  This website is owned and maintained by Packt Publishing Ltd, 2006. All rights reserved. Terms and Conditions