Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Form Processing
 
Article Index
Form Processing
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9

By placing this immediately prior to the form, the result will be a nicely formatted bulleted list of every validation error that occurred.

A complete example of an HTML form that is used with our form validator is shown in :

Listing 5.7. Form Example for the Form Validator Script
<?php if($form_errors): /* An error occurred processing the form */ ?>
<UL>
<?php foreach($form_errorlist as $val): ?>
<LI><?php echo $val;?>
<?php endforeach; ?>
</UL>
<?php endif; ?>

Please fill out the following form (* = Required)<BR>
<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD=GET>
<INPUT TYPE="hidden" NAME="submit" VALUE="1">
<INPUT TYPE="hidden" NAME="required" VALUE="phone,email,fax">
<INPUT TYPE="hidden" NAME="phone_desc" VALUE="Phone Number">
<INPUT TYPE="hidden" NAME="email_desc" VALUE="Email Address">
<INPUT TYPE="hidden" NAME="fax_desc" VALUE="Fax Number">
Your Name: <INPUT TYPE="text" NAME="name"><BR>
* Your Phone Number:
<INPUT TYPE="text" NAME="phone" VALUE="<?php echo $_GET['phone']; ?>"><BR>
* Your Email Address:
<INPUT TYPE="text" NAME="email" VALUE="<?php echo $_GET['email']; ?>"><BR>
* Your Fax Number:
<INPUT TYPE="text" NAME="fax" VALUE="<?php echo $_GET['fax']; ?>"><BR>
<INPUT TYPE="submit" VALUE="Send">
</FORM>

Now that you have an idea of what a form to be used with the form validation script looks like, it's time to move on to the actual PHP script that will process the form. The form validation script is broken up into three separate functions: add_error(), _process_form(), and validate_form(). Of these three functions, validate_form() does the bulk of the work in validating the form data, and add_error() and _process_form() serve as support functions.

As I've already mentioned, validation errors that occur in the form validation script are recorded through the $form_errors and $form_errorlist variables. The add_error() function, as its name implies, is used to manipulate these two variables. Because this function is quite simple, displaying the function should be sufficient for an explanation (see ):

Listing 5.8. The add_error()_Function
<?php
$form_errors = array();
$form_errorlist = false;

function add_error($error) {
global $form_errorlist, $form_errors;
$form_errorlist = true;
$form_errors[] = $error;
}
?>


Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Your Ad Here
Mobile Wallpaper 186
Statistic


Last Post

 
Top! Top!