'[select one]','rant'=>'rant','praise'=>'praise','question'=>'question','observation' =>'observation'); $defaults = array('subject'=>'','comments'=>'','name'=>'','email'=>''); function display_comments() { /* your code here */ } function save_comment($data) { /* your code here */ } function validate_form(&$data) { $errors = array(); $data['email']=trim($data['email']); $data['comments']=trim($data['comments']); $data['name']=trim($data['name']); if (empty($data['email'])) { $errors[] = "Email address is required"; } elseif (! preg_match( '/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i',$data['email'])) { $errors[] = 'Email address appears to be invalid'; } if (empty($data['comments'])) { $errors[] = 'The comments field is required'; } if (strlen($data['comments']) > 250 ) { $errors[] = 'The comments field exceeds the maximum length'; } $data['comments'] = strip_tags($data['comments']); $data['name'] = strip_tags($data['name']); if (! strlen($data['name'])) { $data['name'] = 'anonymous'; } if (strlen($data['name']) > 36) { // truncate it $data['name'] = substr($data['name'],0,36); $errors[] = 'Your name exceeds the max field length' ; } if (empty($data['subject'])) { $errors[] = 'Subject field is required'; } if (! array_key_exists($data['subject'],$GLOBALS['subject_options'])) { $errors[] = 'Invalid subject field'; } return $errors; } /* courtesy of "Learning PHP 5" by David Sklar */ function input_select($element_name, $selected, $options, $multiple = false) { // print out the '; // set up the list of things to be selected $selected_options = array(); if ($multiple) { foreach ($selected[$element_name] as $val) { $selected_options[$val] = true; } } else { $selected_options[ $selected[$element_name] ] = true; } // print out the '; } print ''; } function display_form($defaults) { global $subject_options; ?>
Subject
Your email
Your name
Comments
Sorry, we are unable to process your submission because:

", "

Please correct your form below and re-submit it

"; display_form($_POST); } else { save_comment($_POST) or die("Sorry, our guestbook is out of order. Please try again later"); display_comments() or die("Sorry, our guestbook is out of order. Please try again later"); display_form($defaults); } } else { display_comments() or die("Sorry, our guestbook is out of order. Please try again later");; display_form($defaults); } ?>