'Sesame Seed Puff', 'square' => 'Coconut Milk Gelatin Square', 'cake' => 'Brown Sugar Cake', 'ricemeat' => 'Sweet Rice and Meat'); // Logic to do the right thing based on // the hidden _submit_check parameter if ($_POST['_submit_check']) { // If validate_form( ) returns errors, pass them to show_form( ) if ($form_errors = validate_form( )) { show_form($form_errors); } else { process_form( ); } } else { show_form( ); } // Do something when the form is submitted function process_form( ) { print "You ordered a ". $_POST['order']; } // Display the form function show_form($errors='') { if($errors) { print ""; } print<<<_HTML_
Your Order:
_HTML_; } // Check the form data function validate_form( ) { // Start with an empty array of error messages $errors = array( ); if (! array_key_exists($_POST['order'], $GLOBALS['sweets'])) { $errors[ ] = 'Please choose a valid order.'; } return $errors; } ?>