AJAX - The Complete Reference

(avery) #1

PART II


Chapter 8: User Interface Design for Ajax 393


include("JSON.php");
$json = new Services_JSON();
print $json->encode($matches);
?>

NNOT EOTE If you find that running the ZIP validation example online at http://ajaxref.com/ch8/
zipvalidate.html consistently does not work for U.S. ZIPs, please drop me a line at errata@ajaxref
.com so we can re-evaluate the ZIP service being used. Screen scraping does have its issues!

Another idea of form validation made reasonable with Ajax is the idea of suggesting
solutions to some data entry problems. For example, consider if you ask users to register for
an account on a system you are designing. It would be a good idea to validate that the user
account was available before you let the user go on. Like the previous example, that is easy
enough to perform. However, rather than just outright rejection of the data, you could
generate some available values for the user to pick instead. For example, if the user chose
the account “tpowell” and it was already taken, it could generate a variation of it by adding
a numeric prefix and check to see if it were available. You can see this idea in action in
Figure 8-15 and live at http://ajaxref.com/ch8/validatesuggest.html. We omit the code for
brevity as it adds nothing to the discussion we have not seen already.

FIGURE 8-15 Determine account availability and make a suggestion with Ajax
Free download pdf