The Customer Form
The script customer/details.php
is shown in Example 17-2. If the user is
logged in and validation has not previously failed, the customer data is
retrieved from the customer table and used to
populate the form widgets. If the user isn't logged in, and validation
has not previously failed, a blank form is shown to collect new member
details. If data has failed validation, the form is repopulated and the
error messages are displayed. Error messages and previously entered form
values are stored by the customer/validate.php script in the session
array variables $_SESSION["custFormVars"]
and $_SESSION["custErrors"]
respectively.
The customer form and its widgets are displayed using our winestoreFormTemplate
class that's derived
from the PEAR ITX template class. It's discussed in detail in Chapter 16.
Example 17-2. The customer form script customer/details.php
<?php require_once "DB.php"; require_once "../includes/winestore.inc"; require_once "../includes/authenticate.inc"; require_once "../includes/template.inc"; set_error_handler("customHandler"); // Show meaningful instructions for UPDATE or INSERT if (isset($_SESSION["loginUsername"])) $instructions = "Please amend your details below as required."; else $instructions = "Please fill in the details below to join."; // Takes <form> heading, instructions, action, formVars name, // and formErrors name as parameters $template = new winestoreFormTemplate("Customer Details", $instructions, S_VALIDATE, "custFormVars", "custErrors"); ...
Get Web Database Applications with PHP and MySQL, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.