Chapter6.Creating Web Forms and Validating User Input


Chapter 6. Creating Web Forms and Validating User Input

In this chapter, we're going to develop web applications. The previous chapter gave us the basics of working with HTML controls such as text fields, list boxes, text areas, and so on, but more than that is involved in creating a web application. For example, part of the process often involves validating the data the user sent you to make sure it's in reasonable form before trying to use it.

In this chapter, we'll learn how to determine which browser the user has, validate the data they send us and report errors we want them to fix, redirect users to different URLs, see how to pack an entire web application into one form, and more.

For example, we're going to try to validate the data the user sent by checking whether values that should be integers are truly integers and whether strings hold the data they should with a function named validate_data. The validate_data function will place any errors it finds in a global array that we'll name $errorsand if there are errors, we'll display the errors and ask the user to reenter his or her data. If no errors occurred, we can process the data the user entered. The whole thing will look something like this:

 validate_data(); if(count($errors) != 0){     display_errors();     display_welcome(); } else {     process_data(); } 

Being able to validate data and ask the user to correct any errors like this is an invaluable part of any real web application.



    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net