byronrode Posted May 25, 2006 Share Posted May 25, 2006 Hi there.I am busy putting together a survey engine with an admin backned for a client. The client is an expensive restaurant that runs a survey once/twice a year.I have created the survey, and have got the database submission working perfectly.Checkbox data is imploded into an array, and is comma-seperated, which is then stored in an individual database field.( I opted for this option as there are many checkbox options in the survey, and didn't want to put a major strain on the database as this survey gets about 12000 hits in 1 month )Basically now what is happening is this.If i opt to validate the checkbox data, after submission, the validator says that the checkboxes have not been inputted. If I remove validation on the checkboxes the rest of the survey validates, but in the event that something is left out, when it returns to the form to highlight the missing data, it re-enters all the other inputted information (input boxes | radio boxes | textarea's) but it does not re-check the selected checkboxes.I have tried explode() on the post data, but to no avail.Below is the script that has been written. The error highlighting and re-entering of data has not been continued all the way through, as I would like to figure out the checkboxes before I continue...[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>..Browns of Rivonia..</title><link href="css/survey.css" rel="stylesheet" type="text/css" media="screen" /><script language="JavaScript" type="text/javascript"><!--document.body.style.scrollbarBaseColor='#336633'document.body.style.scrollbarArrowColor='#ffffff'document.body.style.scrollbarDarkShadowColor='#336633'document.body.style.scrollbarFaceColor='#336633'document.body.style.scrollbarHighlightColor='#ffffff'document.body.style.scrollbarShadowColor='#ffffff'document.body.style.scrollbar3dlightColor='#ffffff'--></script></head><body><div id="survey" align="center"> <h1 class="header"><img src="images/brownslogo.gif" alt="Browns Logo" />Annual Customer Satisfaction Survey</h1> <p class="intro"> We are currently doing research in order to ensure that every visit to our restaurant is an unforgettable experience! Please take a minute to complete the questionnaire. Please answer the questions critically - honest answers are of the most value to us! <br /> <br /> Only <strong>FULLY</strong> completed questionnaires that are submitted by the 12th of June 2006 will be entered into a draw to win a meal voucher at Browns, valued at R1000. </p><?phpfunction error_bool($error, $field) { //Highlights incomplete/invalid fields if($error[$field]) { print("<span style=\"color: red; font-weight: bold;\">"); } else { print("<span>"); } }function show_form() { //Starts Validationglobal $HTTP_POST_VARS, $print_again, $error;}if(isset($_POST["Submit"])) { check_form();} else { show_form();}function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true;}function check_form() //Checks input | checkboxes | radio buttons etc except comments which are not compulsory{global $HTTP_POST_VARS, $error, $print_again;$error['name'] = false; if($_POST["name"]=="") { $error['name'] = true; $print_again = true; } if(!check_email_address($_POST['email'])) { $error['email'] = true; $print_again = true; } if($_POST["contactnumber"]=="") { $error['contactnumber'] = true; $print_again = true; } if($_POST["age"]=="") { $error['age'] = true; $print_again = true; } if($_POST["maritalstatus"]=="") { $error['maritalstatus'] = true; $print_again = true; } if($_POST["gender"]=="") { $error['gender'] = true; $print_again = true; } if($_POST["live"]=="") { $error['live'] = true; $print_again = true; } if($_POST["work"]=="") { $error['work'] = true; $print_again = true; } if($_POST["radiostations[]"]=="") { $error['radiostations[]'] = true; $print_again = true; } if($_POST["hobbiesinterests[]"]=="") { $error['hobbiesinterests[]'] = true; $print_again = true; } if($_POST["emailcorr"]=="") { $error['emailcorr'] = true; $print_again = true; } if($_POST["othercorr"]=="") { $error['othercorr'] = true; $print_again = true; } if($_POST["heardaboutus"]=="") { $error['heardaboutus'] = true; $print_again = true; } if($_POST["sitefreq"]=="") { $error['sitefreq'] = true; $print_again = true; } if($_POST["restselect"]=="") { $error['reselect'] = true; $print_again = true; } if($_POST["kidsu14"]=="") { $error['kidsu14'] = true; $print_again = true; } if($_POST["allowkidsu14"]=="") { $error['allowkidsu14'] = true; $print_again = true; } if($_POST["lastate"]=="") { $error['lastate'] = true; $print_again = true; } if($_POST["visitbrowns"]=="") { $error['visitbrowns'] = true; $print_again = true; } if($_POST["wellsignpst"]=="") { $error['wellsignpst'] = true; $print_again = true; } if($_POST["enoughprk"]=="") { $error['enoughprk'] = true; $print_again = true; } if($_POST["secureprk"]=="") { $error['secureprk'] = true; $print_again = true; } if($_POST["friendlygrt"]=="") { $error['friendlygrt'] = true; $print_again = true; } if($_POST["restclean"]=="") { $error['restclean'] = true; $print_again = true; } if($_POST["bathcleanrep"]=="") { $error['bathcleanrep'] = true; $print_again = true; } if($_POST["threebestfeat"]=="") { $error['threebestfeat'] = true; $print_again = true; } if($_POST["prefseat"]=="") { $error['prefseat'] = true; $print_again = true; } if($_POST["meetmulti"]=="") { $error['meetmulti'] = true; $print_again = true; } if($_POST["danhill"]=="") { $error['danhill'] = true; $print_again = true; } if($_POST["twentyccjazz"]=="") { $error['twentyccjazz'] = true; $print_again = true; } if($_POST["twojazzeve"]=="") { $error['twojazzeve'] = true; $print_again = true; } if($_POST["ratealacarte"]=="") { $error['ratealacarte'] = true; $print_again = true; } if($_POST["ratestarters"]=="") { $error['ratestarters'] = true; $print_again = true; } if($_POST["ratemains"]=="") { $error['ratemains'] = true; $print_again = true; } if($_POST["ratedess"]=="") { $error['ratedess'] = true; $print_again = true; } if($_POST["ratemenuchg"]=="") { $error['ratemenuchg'] = true; $print_again = true; } if($_POST["ratefdqual"]=="") { $error['ratefdqual'] = true; $print_again = true; } if($_POST["favefood"]=="") { $error['favefood'] = true; $print_again = true; } if($_POST["foodprblm"]=="") { $error['foodprblm'] = true; $print_again = true; } if($_POST["foodprc"]=="") { $error['foodprc'] = true; $print_again = true; } if($_POST["waitpolfrnd"]=="") { $error['waitpolfrnd'] = true; $print_again = true; } if($_POST["waiteff"]=="") { $error['waiteff'] = true; $print_again = true; } if($_POST["lvlofattn"]=="") { $error['lvlofattn'] = true; $print_again = true; } if($_POST["knowwine"]=="") { $error['knowwine'] = true; $print_again = true; } if($_POST["critosr"]=="") { $error['critosr'] = true; $print_again = true; } if($_POST["mngeff"]=="") { $error['mngeff'] = true; $print_again = true; } if($_POST["ordwine"]=="") { $error['ordwine'] = true; $print_again = true; } if($_POST["winetour"]=="") { $error['winetour'] = true; $print_again = true; } if($_POST["wineval"]=="") { $error['wineval'] = true; $print_again = true; } if($_POST["wineselect"]=="") { $error['wineselect'] = true; $print_again = true; } if($_POST["rateday"]=="") { $error['rateday'] = true; $print_again = true; } if($_POST["ratenight"]=="") { $error['ratenight'] = true; $print_again = true; } if($_POST["ratebgmusic"]=="") { $error['ratebgmusic'] = true; $print_again = true; } if($_POST["ratelight"]=="") { $error['ratelight'] = true; $print_again = true; } if($_POST["chsroom"]=="") { $error['chsroom'] = true; $print_again = true; } if($_POST["vstchsroom"]=="") { $error['vstchsroom'] = true; $print_again = true; } if($_POST["ordchs"]=="") { $error['ordchs'] = true; $print_again = true; } if($_POST["ratechssel"]=="") { $error['ratechssel'] = true; $print_again = true; } if($_POST["chstypes"]=="") { $error['chstypes'] = true; $print_again = true; } if($_POST["wineeve"]=="") { $error['wineeve'] = true; $print_again = true; } if($_POST["eventapp"]=="") { $error['eventapp'] = true; $print_again = true; } if($_POST["oftatt"]=="") { $error['oftatt'] = true; $print_again = true; } if($_POST["oftevetp"]=="") { $error['oftevetp'] = true; $print_again = true; } if($_POST["ratewine"]=="") { $error['ratewine'] = true; $print_again = true; } if($print_again) { show_form(); echo("<div class=\"errorheader\">The fields highlighted in RED are required. Please go through the survey again and fill in the missing data</div>"); //Prints Warning } else { show_form(); // Get Form Data // Implode Checkboxes to Form an Array for database storage // Demographics $id = $_POST['id']; $name = $_POST['name']; $date = date('j F Y'); $time = date('g:i a'); $email = $_POST['email']; $contactnumber = $_POST['contactnumber']; $age = $_POST['age']; $maritalstatus = $_POST['maritalstatus']; $gender = $_POST['gender']; $live = $_POST['live']; $work = $_POST['work']; if(isset($_POST['radiostations'])) { $radiostations = implode(', ' , $_POST['radiostations']); } else { $rediostations = "None Selected"; } if(isset($_POST['hobbiesinterests'])) { $hobbiesinterests = implode(', ' , $_POST['hobbiesinterests']); } else { $hobbiesinterests = "None Selected"; } // Marketing $emailcorr = $_POST['emailcorr']; if(isset($_POST['othercorr'])) { $othercorr = implode(', ' , $_POST['othercorr']); } else { $othercorr = "None Selected"; } $heardaboutus = $_POST['heardaboutus']; $sitefreq = $_POST['sitefreq']; $restselect = $_POST['restselect']; $kidsu14 = $_POST['kidsu14']; if(isset($_POST['allowkidsu14'])) { $allowkidsu14 = implode(', ' , $_POST['allowkidsu14']); } else { $allowkidsu14 = "None Selected"; } $othcom_market = $_POST['othcom_market']; // The Restaurant $lastate = $_POST['lastate']; $visitbrowns = $_POST['visitbrowns']; $wellsignpst = $_POST['wellsignpst']; $enoughprk = $_POST['enoughprk']; $secureprk = $_POST['secureprk']; $friendlygrt = $_POST['friendlygrt']; $restclean = $_POST['restclean']; $bathcleanrep = $_POST['bathcleanrep']; if(isset($_POST['threebestfeat'])) { $threebestfeat = implode(', ' , $_POST['threebestfeat']); } else { $threebestfeat = "None Selected"; } $prefseat = $_POST['prefseat']; $brownslnch = $_POST['brownslnch']; $ifno = $_POST['ifno']; $meetmulti = $_POST['meetmulti']; $danhill = $_POST['danhill']; $twentyccjazz = $_POST['twentyccjazz']; if(isset($_POST['twojazzeve'])) { $twojazzeve = implode(', ' , $_POST['twojazzeve']); } else { $twojazzeve = "None Selected"; } $gencomm = $_POST['gencomm']; // Menu $ratealacarte = $_POST['ratealacarte']; $ratelunch = $_POST['ratelunch']; $ratestarters = $_POST['ratestarters']; $ratemains = $_POST['ratemains']; $ratedess = $_POST['ratedess']; $ratemenuchg = $_POST['ratemenuchg']; $ratefdqual = $_POST['ratefdqual']; if(isset($_POST['favefood'])) { $favefood = implode(', ' , $_POST['favefood']); } else { $favefood = "None Selected"; } $foodprblm = $_POST['foodprblm']; $ifexper = $_POST['ifexper']; $foodprc = $_POST['foodprc']; $othcom_menu = $_POST['othcom_menu']; // Service $waitpolfrnd = $_POST['waitpolfrnd']; $waiteff = $_POST['waiteff']; $lvlofattn = $_POST['lvlofattn']; $knowwine = $_POST['knowwine']; $critosr = $_POST['critosr']; $mngeff = $_POST['mngeff']; $othcom_serv = $_POST['othcom_serv']; // Wine $ordwine = $_POST['ordwine']; $winetour = $_POST['winetour']; $wineval = $_POST['wineval']; $wineselect = $_POST['wineselect']; $othcom_wine = $_POST['othcom_wine']; // Ambience $rateday = $_POST['rateday']; $ratenight = $_POST['ratenight']; $ratebgmusic = $_POST['ratebgmusic']; $ratelight = $_POST['ratelight']; $othcom_amb = $_POST['othcom_amb']; // Cheese Room $chsroom = $_POST['chsroom']; $vstchsroom = $_POST['vstchsroom']; $ordchs = $_POST['ordchs']; $ratechssel = $_POST['ratechssel']; if(isset($_POST['chstypes'])) { $chstypes = implode(', ' , $_POST['chstypes']); } else { $chstypes = "None Selected"; } $othcom_chs = $_POST['othcom_chs']; // Wine Evenings $wineeve = $_POST['wineeve']; $eventapp = $_POST['eventapp']; $oftatt = $_POST['oftatt']; $oftevetp = $_POST['oftevetp']; $ratewine = $_POST['ratewine']; // Miscellaneous $othcom_wineeve = $_POST['othcom_wineeve']; $othcom_browns = $_POST['othcom_browns']; // Open Database Connection require_once("includes/dbconnect.php"); // Escape Quotes function quote_smart($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not numeric if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } return $value; } function nl2br_pre($string, $wrap = 40) { $string = nl2br($string); preg_match_all("/<pre[^>]*?>(.|\n)*?<\/pre>/", $string, $pre1); for ($x = 0; $x < count($pre1[0]); $x++) { $pre2[$x] = preg_replace("/\s*<br[^>]*?>\s*/", "", $pre1[0][$x]); $pre2[$x] = preg_replace("/([^\n]{".$wrap."})(?!<\/pre>)(?!\n)/", "$1\n", $pre2[$x]); $pre1[0][$x] = "/".preg_quote($pre1[0][$x], "/")."/"; } return preg_replace($pre1[0], $pre2, $string); } $datasubmission = mysql_query ("INSERT INTO `survey` ( `id` , `date` , `time` , `name` , `email` , `contactnumber` , `age` , `maritalstatus` , `gender` , `live` , `work` , `radiostations` , `hobbiesinterests` , `emailcorr` , `othercorr` , `heardaboutus` , `sitefreq` , `restselect` , `kidsu14` , `allowkidsu14` , `othcom_market` , `lastate` , `visitbrowns` , `wellsignpst` , `enoughprk` , `secureprk` , `friendlygrt` , `restclean` , `bathcleanrep` , `threebestfeat` , `prefseat` , `brownslnch` , `ifno` , `meetmulti` , `danhill` , `twentyccjazz` , `twojazzeve` , `gencomm` , `ratealacarte` , `ratelunch` , `ratestarters` , `ratemains` , `ratedess` , `ratemenuchg` , `ratefdqual` , `favefood` , `foodprblm` , `ifexper` , `foodprc` , `othcom_menu` , `waitpolfrnd` , `waiteff` , `lvlofattn` , `knowwine` , `critosr` , `mngeff` , `othcom_serv` , `ordwine` , `winetour` , `wineval` , `wineselect` , `othcom_wine` , `rateday` , `ratenight` , `ratebgmusic` , `ratelight` , `othcom_amb` , `chsroom` , `vstchsroom` , `ordchs` , `ratechssel` , `chstypes` , `othcom_chs` , `wineeve` , `eventapp` , `oftatt` , `oftevetp` , `ratewine` , `othcom_wineeve` , `othcom_browns` )". "VALUES ( '$id', '$date', '$time', '$name', '$email', '$contactnumber', '$age', '$maritalstatus', '$gender', '$live', '$work', '$radiostations', '$hobbiesinterests', '$emailcorr', '$othercorr', '$heardaboutus', '$sitefreq', '$restselect', '$kidsu14', '$allowkidsu14', '$othcom_market', '$lastate', '$visitbrowns', '$wellsignpst', '$enoughprk', '$secureprk', '$friendlygrt', '$restclean', '$bathcleanrep', '$threebestfeat', '$prefseat', '$brownslnch', '$ifno', '$meetmulti', '$danhill', '$twentyccjazz', '$twojazzeve', '$gencomm', '$ratealacarte', '$ratelunch', '$ratestarters', '$ratemains', '$ratedess', '$ratemenuchg', '$ratefdqual', '$favefood', '$foodprblm', '$ifexper', '$foodprc', '$othcom_menu', '$waitpolfrnd', '$waiteff', '$lvlofattn', '$knowwine', '$critosr', '$mngeff', '$othcom_serv', '$ordwine', '$winetour', '$wineval', '$wineselect', '$othcom_wine', '$rateday', '$ratenight', '$ratebgmusic', '$ratelight', '$othcom_amb', '$chsroom', '$vstchsroom', '$ordchs', '$ratechssel', '$chstypes', '$othcom_chs', '$wineeve', '$eventapp', '$oftatt', '$oftevetp', '$ratewine', '$othcom_wineeve', '$othcom_browns')"); // Close Database require_once("includes/dbdisconnect.php"); ?> <?php //Success include ("success.html"); // Submission Successful exit; // Ensures no scripts or HTML run after submission is successful } }?><!-- Start: Survey Form --> <form method="post" action="<?php echo $PHP_SELF; ?>" ><!-- Start: Demographics --> <div class="category">Demographics</div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Name & Surname :</span></div> <div class="cat_input"><input name="name" type="text" size="50" maxlength="100" value="<?php echo $_POST["name"]; ?>" /></div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "email"); ?>Email Address :</span></div> <div class="cat_input"><input name="email" type="text" size="50" maxlength="100" value="<?php echo $_POST["email"]; ?>" /></div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "contactnumber"); ?>Contact Number :</span></div> <div class="cat_input"><input name="contactnumber" type="text" size="50" maxlength="100" value="<?php echo $_POST["contactnumber"]; ?>" /></div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "age"); ?>Your age :</span></div> <div class="cat_input"> <select name="age"> <option value="">Make A Selection</option> <option value="20-25"<?php if($_POST['age'] == "20-25") echo " selected=\"selected\""; ?>>20-25</option> <option value="26-30"<?php if($_POST['age'] == "26-30") echo " selected=\"selected\""; ?>>26-30</option> <option value="31-35"<?php if($_POST['age'] == "31-35") echo " selected=\"selected\""; ?>>31-35</option> <option value="36-40"<?php if($_POST['age'] == "36-40") echo " selected=\"selected\""; ?>>36-40</option> <option value="41-45"<?php if($_POST['age'] == "41-45") echo " selected=\"selected\""; ?>>41-45</option> <option value="46-50"<?php if($_POST['age'] == "46-50") echo " selected=\"selected\""; ?>>46-50</option> <option value="Over 50"<?php if($_POST['age'] == "Over 50") echo " selected=\"selected\""; ?>>Over 50</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "maritalstatus"); ?>Marital status :</span></div> <div class="cat_input"> <input type="radio" name="maritalstatus" value="Married"<?php if($_POST['maritalstatus'] == "Married") echo " checked=\"checked\""; ?> />Married <input type="radio" name="maritalstatus" value="Single"<?php if($_POST['maritalstatus'] == "Single") echo " checked=\"checked\""; ?> />Single </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "gender"); ?>Gender :</span></div> <div class="cat_input"> <input type="radio" name="gender" value="Male"<?php if($_POST['gender'] == "Male") echo " checked=\"checked\""; ?> />Male <input type="radio" name="gender" value="Female"<?php if($_POST['gender'] == "Female") echo " checked=\"checked\""; ?> />Female </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "live"); ?>Where do you live?</span></div> <div class="cat_input"> <select name="live"> <option value="">Make A Selection</option> <option value="Bedfordview"<?php if($_POST['live'] == "Bedfordview") echo " selected=\"selected\""; ?>>Bedfordview</option> <option value="Benoni"<?php if($_POST['live'] == "Benoni") echo " selected=\"selected\""; ?>>Benoni</option> <option value="Boksburg"<?php if($_POST['live'] == "Boksburg") echo " selected=\"selected\""; ?>>Boksburg</option> <option value="Brakpan"<?php if($_POST['live'] == "Brakpan") echo " selected=\"selected\""; ?>>Brakpan</option> <option value="Broadacres"<?php if($_POST['live'] == "Broadacres") echo " selected=\"selected\""; ?>>Broadacres</option> <option value="Bryanston"<?php if($_POST['live'] == "Bryanston") echo " selected=\"selected\""; ?>>Bryanston</option> <option value="Centurion"<?php if($_POST['live'] == "Centurion") echo " selected=\"selected\""; ?>>Centurion</option> <option value="Douglasdale"<?php if($_POST['live'] == "Douglasdale") echo " selected=\"selected\""; ?>>Douglasdale</option> <option value="Edenvale"<?php if($_POST['live'] == "Edenvale") echo " selected=\"selected\""; ?>>Edenvale</option> <option value="Fourways"<?php if($_POST['live'] == "Fourways") echo " selected=\"selected\""; ?>>Fourways</option> <option value="Hyde Park"<?php if($_POST Quote Link to comment https://forums.phpfreaks.com/topic/10421-php-form-validation/ Share on other sites More sharing options...
byronrode Posted May 25, 2006 Author Share Posted May 25, 2006 The rest of the script (it was cut off)[code]<option value="Hyde Park"<?php if($_POST['live'] == "Hyde Park") echo " selected=\"selected\""; ?>>Hyde Park</option> <option value="Illovo"<?php if($_POST['live'] == "Illovo") echo " selected=\"selected\""; ?>>Illovo</option> <option value="JHB Southern Suburbs"<?php if($_POST['live'] == "JHB Southern Suburbs") echo " selected=\"selected\""; ?>>JHB Southern Suburbs</option> <option value="Kempton Park"<?php if($_POST['live'] == "Kempton Park") echo " selected=\"selected\""; ?>>Kempton Park</option> <option value="Killarney"<?php if($_POST['live'] == "Killarney") echo " selected=\"selected\""; ?>>Killarney</option> <option value="Krugersdorp"<?php if($_POST['live'] == "Krugersdorp") echo " selected=\"selected\""; ?>>Krugersdorp</option> <option value="Kyalami"<?php if($_POST['live'] == "Kyalami") echo " selected=\"selected\""; ?>>Kyalami</option> <option value="Lonehill"<?php if($_POST['live'] == "Lonehill") echo " selected=\"selected\""; ?>>Lonehill</option> <option value="Midrand"<?php if($_POST['live'] == "Midrand") echo " selected=\"selected\""; ?>>Midrand</option> <option value="Morningside"<?php if($_POST['live'] == "Morningside") echo " selected=\"selected\""; ?>>Morningside</option> <option value="Norwood"<?php if($_POST['live'] == "Norwood") echo " selected=\"selected\""; ?>>Norwood</option> <option value="Rivonia"<?php if($_POST['live'] == "Rivonia") echo " selected=\"selected\""; ?>>Rivonia</option> <option value="Parkmore"<?php if($_POST['live'] == "Parkmore") echo " selected=\"selected\""; ?>>Parkmore</option> <option value="Parktown"<?php if($_POST['live'] == "Parktown") echo " selected=\"selected\""; ?>>Parktown</option> <option value="Parkhurst"<?php if($_POST['live'] == "Parkhurst") echo " selected=\"selected\""; ?>>Parkhurst</option> <option value="Pretoria"<?php if($_POST['live'] == "Pretoria") echo " selected=\"selected\""; ?>>Pretoria</option> <option value="Randburg"<?php if($_POST['live'] == "Randburg") echo " selected=\"selected\""; ?>>Randburg</option> <option value="Roodepoort"<?php if($_POST['live'] == "Roodepoort") echo " selected=\"selected\""; ?>>Roodepoort</option> <option value="Sandhurst"<?php if($_POST['live'] == "Sandhurst") echo " selected=\"selected\""; ?>>Sandhurst</option> <option value="Sandton"<?php if($_POST['live'] == "Sandton") echo " selected=\"selected\""; ?>>Sandton</option> <option value="Sunninghill"<?php if($_POST['live'] == "Sunninghill") echo " selected=\"selected\""; ?>>Sunninghill</option> <option value="I do not live in Gauteng"<?php if($_POST['live'] == "I do not live in Gauteng") echo " selected=\"selected\""; ?>>I do not live in Gauteng</option> <option value="I do not live in South Africa"<?php if($_POST['live'] == "I do not live in South Africa") echo " selected=\"selected\""; ?>>I do not live in South Africa</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "work"); ?>Where do you work?</span></div> <div class="cat_input"> <select name="work"> <option value="">Make A Selection</option> <option value="Bedfordview"<?php if($_POST['work'] == "Bedfordview") echo " selected=\"selected\""; ?>>Bedfordview</option> <option value="Benoni"<?php if($_POST['work'] == "Benoni") echo " selected=\"selected\""; ?>>Benoni</option> <option value="Boksburg"<?php if($_POST['work'] == "Boksburg") echo " selected=\"selected\""; ?>>Boksburg</option> <option value="Brakpan"<?php if($_POST['work'] == "Brakpan") echo " selected=\"selected\""; ?>>Brakpan</option> <option value="Broadacres"<?php if($_POST['work'] == "Broadacres") echo " selected=\"selected\""; ?>>Broadacres</option> <option value="Bryanston"<?php if($_POST['work'] == "Bryanston") echo " selected=\"selected\""; ?>>Bryanston</option> <option value="Centurion"<?php if($_POST['work'] == "Centurion") echo " selected=\"selected\""; ?>>Centurion</option> <option value="Douglasdale"<?php if($_POST['work'] == "Douglasdale") echo " selected=\"selected\""; ?>>Douglasdale</option> <option value="Edenvale"<?php if($_POST['work'] == "Edenvale") echo " selected=\"selected\""; ?>>Edenvale</option> <option value="Fourways"<?php if($_POST['work'] == "Fourways") echo " selected=\"selected\""; ?>>Fourways</option> <option value="Hyde Park"<?php if($_POST['work'] == "Hyde Park") echo " selected=\"selected\""; ?>>Hyde Park</option> <option value="Illovo"<?php if($_POST['work'] == "Illovo") echo " selected=\"selected\""; ?>>Illovo</option> <option value="JHB Southern Suburbs"<?php if($_POST['work'] == "JHB Southern Suburbs") echo " selected=\"selected\""; ?>>JHB Southern Suburbs</option> <option value="Johannesburg Central"<?php if($_POST['work'] == "Johannesburg Central") echo " selected=\"selected\""; ?>>Johannesburg Central</option> <option value="Kempton Park"<?php if($_POST['work'] == "Kempton Park") echo " selected=\"selected\""; ?>>Kempton Park</option> <option value="Killarney"<?php if($_POST['work'] == "Killarney") echo " selected=\"selected\""; ?>>Killarney</option> <option value="Krugersdorp"<?php if($_POST['work'] == "Krugersdorp") echo " selected=\"selected\""; ?>>Krugersdorp</option> <option value="Kyalami"<?php if($_POST['work'] == "Kyalami") echo " selected=\"selected\""; ?>>Kyalami</option> <option value="Lonehill"<?php if($_POST['work'] == "Lonehill") echo " selected=\"selected\""; ?>>Lonehill</option> <option value="Midrand"<?php if($_POST['work'] == "Midrand") echo " selected=\"selected\""; ?>>Midrand</option> <option value="Morningside"<?php if($_POST['work'] == "Morningside") echo " selected=\"selected\""; ?>>Morningside</option> <option value="Norwood"<?php if($_POST['work'] == "Norwood") echo " selected=\"selected\""; ?>>Norwood</option> <option value="Rivonia"<?php if($_POST['work'] == "Rivonia") echo " selected=\"selected\""; ?>>Rivonia</option> <option value="Parkmore"<?php if($_POST['work'] == "Parkmore") echo " selected=\"selected\""; ?>>Parkmore</option> <option value="Parktown"<?php if($_POST['work'] == "Parktown") echo " selected=\"selected\""; ?>>Parktown</option> <option value="Parkhurst"<?php if($_POST['work'] == "Parkhurst") echo " selected=\"selected\""; ?>>Parkhurst</option> <option value="Pretoria"<?php if($_POST['work'] == "Pretoria") echo " selected=\"selected\""; ?>>Pretoria</option> <option value="Randburg"<?php if($_POST['work'] == "Randburg") echo " selected=\"selected\""; ?>>Randburg</option> <option value="Roodepoort"<?php if($_POST['work'] == "Roodepoort") echo " selected=\"selected\""; ?>>Roodepoort</option> <option value="Sandhurst"<?php if($_POST['work'] == "Sandhurst") echo " selected=\"selected\""; ?>>Sandhurst</option> <option value="Sandton"<?php if($_POST['work'] == "Sandton") echo " selected=\"selected\""; ?>>Sandton</option> <option value="Sunninghill"<?php if($_POST['work'] == "Sunninghill") echo " selected=\"selected\""; ?>>Sunninghill</option> <option value="I do not work in Gauteng"<?php if($_POST['work'] == "I do not work in Gauteng") echo " selected=\"selected\""; ?>>I do not work in Gauteng</option> <option value="I do not work in South Africa"<?php if($_POST['work'] == "I do not work in South Africa") echo " selected=\"selected\""; ?>>I do not work in South Africa</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "radiostations[]"); ?>What radio stations do you listen to?</span></div> <div class="cat_input"> <input type="checkbox" name="radiostations[]" value="I don't listen to the radio"<?php if($_POST['radiostations[]'] == "I don't listen to the radio") echo " checked=\"checked\""; ?> />I don't listen to the radio<br /> <input type="checkbox" name="radiostations[]" value="94.7 Highveld Stereo"<?php if($_POST['radiostations[]'] == "94.7 Highveld Stereo") echo " checked=\"checked\""; ?> />94.7 Highveld Stereo<br /> <input type="checkbox" name="radiostations[]" value="Jacaranda FM"<?php if($_POST['radiostations[]'] == "Jacaranda FM") echo " checked=\"checked\""; ?> />Jacaranda FM<br /> <input type="checkbox" name="radiostations[]" value="Kaya FM"<?php if($_POST['radiostations[]'] == "Kaya FM") echo " checked=\"checked\""; ?> />Kaya FM<br /> <input type="checkbox" name="radiostations[]" value="Classic FM"<?php if($_POST['radiostations[]'] == "Classic FM") echo " checked=\"checked\""; ?> />Classic FM<br /> <input type="checkbox" name="radiostations[]" value="5 FM"<?php if($_POST['radiostations[]'] == "5 FM") echo " checked=\"checked\""; ?> />5 FM<br/> <input type="checkbox" name="radiostations[]" value="Metro FM"<?php if($_POST['radiostations[]'] == "Metro FM") echo " checked=\"checked\""; ?> />Metro FM<br /><br /> Other: <input maxlength="20" name="radiostations[]" value="<?php echo $_POST["radiostations[]"]; ?>" /> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "hobbiesinterests[]"); ?>Hobbies or interests: </span></div> <div class="cat_input"> <input type="checkbox" value="Golf" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests'] == "Golf") echo " checked=\"checked\""; ?> />Golf<br /> <input type="checkbox" value="Motoring" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Motoring") echo " checked=\"checked\""; ?> />Motoring<br /> <input type="checkbox" value="Cricket" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Cricket") echo " checked=\"checked\""; ?> />Cricket<br /> <input type="checkbox" value="Computers" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Computers") echo " checked=\"checked\""; ?> />Computers<br /> <input type="checkbox" value="Reading" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Reading") echo " checked=\"checked\""; ?> />Reading<br /> <input type="checkbox" value="Gardening" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Gardening") echo " checked=\"checked\""; ?> />Gardening<br /> <input type="checkbox" value="Travel" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Travel") echo " checked=\"checked\""; ?> />Travel<br /> <input type="checkbox" value="Wine" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Wine") echo " checked=\"checked\""; ?> />Wine<br /> <input type="checkbox" value="Hiking/Walking" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Hiking/Walking") echo " checked=\"checked\""; ?> />Hiking/Walking<br /> <input type="checkbox" value="Jogging" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Jogging") echo " checked=\"checked\""; ?> />Jogging<br /> <input type="checkbox" value="Cycling" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Cycling") echo " checked=\"checked\""; ?> />Cycling<br /> <input type="checkbox" value="Watersports" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Watersports") echo " checked=\"checked\""; ?> />Watersports<br /> <input type="checkbox" value="Rugby" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Rugby") echo " checked=\"checked\""; ?> />Rugby<br /> <input type="checkbox" value="Soccer" name="hobbiesinterests[]"<?php if($_POST['hobbiesinterests[]'] == "Soccer") echo " checked=\"checked\""; ?> />Soccer<br /> <br /> Other: <input maxlength="30" size="30" name="hobbiesinterests[]" value="<?php echo $_POST["hobbiesinterests[]"]; ?>" /> </div> </div> <!-- End: Demographics --> <!-- Start: Marketing --> <div class="category">Marketing</div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "emailcorr"); ?>How do you find our email correspondence?</span></div> <div class="cat_input"> <select name="emailcorr"> <option value="">Make A Selection</option> <option value="Informative"<?php if($_POST['emailcorr'] == "Informative") echo " selected=\"selected\""; ?>>Informative</option> <option value="Intrusive"<?php if($_POST['emailcorr'] == "Intrusive") echo " selected=\"selected\""; ?>>Intrusive</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "othercorr"); ?>What would you like to receive correspondence about?</span></div> <div class="cat_input"> <input type="checkbox" name="othercorr[]" value="Menu changes" />Menu changes <input type="checkbox" name="othercorr[]" value="Upcoming events" />Upcoming events<br /> <input type="checkbox" name="othercorr[]" value="Wine related matters" />Wine related matters<br /> Other: <input type="text" name="othercorr[]" size="54" /> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "heardaboutus"); ?>Where did you initially hear about Browns?</span></div> <div class="cat_input"> <select name="heardaboutus"> <option value="">Make A Selection</option> <option value="Print Media"<?php if($_POST['heardaboutus'] == "Print Media") echo " selected=\"selected\""; ?>>Print Media</option> <option value="Radio"<?php if($_POST['heardaboutus'] == "Radio") echo " selected=\"selected\""; ?>>Radio</option> <option value="Word of mouth"<?php if($_POST['heardaboutus'] == "Word of mouth") echo " selected=\"selected\""; ?>>Word of mouth</option> <option value="Internet"<?php if($_POST['heardaboutus'] == "Internet") echo " selected=\"selected\""; ?>>Internet</option> <option value="Street Billboards"<?php if($_POST['heardaboutus'] == "Street Billboards") echo " selected=\"selected\""; ?>>Street Billboards</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "sitefreq"); ?>How often do you visit the Browns website <strong>www.browns.co.za</strong>?</span></div> <div class="cat_input"> <select name="sitefreq"> <option value="">Make A Selection</option> <option value="More Than Once A Month"<?php if($_POST['sitefreq'] == "More Than Once A Month") echo " selected=\"selected\""; ?>>More Than Once A Month</option> <option value="Once A Month"<?php if($_POST['sitefreq'] == "Once A Month") echo " selected=\"selected\""; ?>>Once A Month</option> <option value="Less Than Once A Month"<?php if($_POST['sitefreq'] == "Less Than Once A Month") echo " selected=\"selected\""; ?>>Less Than Once A Month</option> <option value="I have never visited the Browns website"<?php if($_POST['sitefreq'] == "I have never visited the Browns website") echo " selected=\"selected\""; ?>>I have never visited the Browns website</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>When choosing a restaurant, you look to :</span></div> <div class="cat_input"> <input type="radio" name="restselect" value="Newspapers"<?php if($_POST['restselect'] == "") echo " checked=\"checked\""; ?> />Newspapers <input type="radio" name="restselect" value="Community newspapers" />Community newspapers<br /> <input type="radio" name="restselect" value="Radio" />Radio <input type="radio" name="restselect" value="Web searches" />Web searches<br /> <input type="radio" name="restselect" value="Restaurant Guides" />Restaurant Guides <input type="radio" name="restselect" value="Magazines" />Magazine </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Does the fact that Browns does not allow children under 14 affect your choice?</span></div> <div class="cat_input"> <input type="radio" name="kidsu14" value="Yes" />Yes <input type="radio" name="kidsu14" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Should Browns allow children under 14?</span></div> <div class="cat_input"> <input type="checkbox" name="allowkidsu14[]" value="Not at all" />Not at all<br /> <input type="checkbox" name="allowkidsu14[]" value="On Sundays" />On Sundays<br /> <input type="checkbox" name="allowkidsu14[]" value="Mothers Day & Fathers Day" />Mothers Day & Fathers Day<br /> <input type="checkbox" name="allowkidsu14[]" value="Friday & Saturday Night" />Friday & Saturday Night<br /> <input type="checkbox" name="allowkidsu14[]" value="All the time" />All the time </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Other comments on Marketing :</span></div> <div class="cat_input"> <textarea name="othcom_market" cols="40" rows="5"></textarea> </div> </div> <!-- End: Marketing --> <!-- Start: The Restaurant --> <div class="category">The Restaurant</div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>I last ate at Browns :</span></div> <div class="cat_input"> <select name="lastate"> <option value="">Make A Selection</option> <option value="Less than 1 month ago">Less than 1 month ago</option> <option value="Less than 3 months ago">Less than 3 months ago</option> <option value="Less than 6 months ago">Less than 6 months ago</option> <option value="More than 6 months ago">More than 6 months ago</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>I visit Browns on :</span></div> <div class="cat_input"> <select name="visitbrowns"> <option value="">Make A Selection</option> <option value="Regular business occasions">Regular business occasions</option> <option value="Special business occasions">Special business occasions</option> <option value="Regular social occasions">Regular social occasions</option> <option value="Special social occasions">Special social occasions</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Is Browns restaurant well sign posted?</span></div> <div class="cat_input"> <input type="radio" name="wellsignpst" value="Yes" />Yes <input type="radio" name="wellsignpst" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Is there enough parking?</span></div> <div class="cat_input"> <input type="radio" name="enoughprk" value="Yes" />Yes <input type="radio" name="enoughprk" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Is the parking secure?</span></div> <div class="cat_input"> <input type="radio" name="secureprk" value="Yes" />Yes <input type="radio" name="secureprk" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Was the greeting upon arrival friendly?</span></div> <div class="cat_input"> <input type="radio" name="friendlygrt" value="Yes" />Yes <input type="radio" name="friendlygrt" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Did you find the restaurant clean?</span></div> <div class="cat_input"> <input type="radio" name="restclean" value="Yes" />Yes <input type="radio" name="restclean" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Did you find the bathrooms clean and presentable?</span></div> <div class="cat_input"> <input type="radio" name="bathcleanrep" value="Yes" />Yes <input type="radio" name="bathcleanrep" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>What, in your opinion, are the best features of Browns?(choose 3)</div> <div class="cat_input"> <input type="checkbox" name="threebestfeat[]" value="The Food" />The Food<br /> <input type="checkbox" name="threebestfeat[]" value="The Wine" />The Wine<br /> <input type="checkbox" name="threebestfeat[]" value="The Service" />The Service<br /> <input type="checkbox" name="threebestfeat[]" value="The Ambience" />The Ambience<br /> <input type="checkbox" name="threebestfeat[]" value="The Live Jazz" />The Live Jazz<br /> <input type="checkbox" name="threebestfeat[]" value="The Wine Evening" />The Wine Evenings<br /> <input type="checkbox" name="threebestfeat[]" value="The Wine Cellar" />The Wine Cellar<br /> <input type="checkbox" name="threebestfeat[]" value="The Cheese Room" />The Cheese Room<br /> <input type="checkbox" name="threebestfeat[]" value="The Gardens" />The Gardens<br /> <input type="checkbox" name="threebestfeat[]" value="The Restrooms" />The Restrooms<br /> <input type="checkbox" name="threebestfeat[]" value="Dinner & Dance Evenings" />Dinner & Dance Evenings </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Do you prefer to sit :</span></div> <div class="cat_input"> <select name="prefseat"> <option value="">Make A Selection</option> <option value="Original Farmhouse Section (inside)">Original Farmhouse Section (inside)</option> <option value="On The Patio (inside)">On The Patio (inside)</option> <option value="On the wooden decks (outside)">On the wooden decks (outside)</option> <option value="In the wine cellar">In the wine cellar</option> </select> </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>Would you consider popping into Browns for a quick lunch?</span></div> <div class="cat_input"> <input type="radio" name="brownslnch" value="Yes" />Yes <input type="radio" name="brownslnch" value="No" />No </div> </div> <div class="cat_container"> <div class="cat_label_float"><?php error_bool($error, "name"); ?>If No, why Not?</span></div> <div class="cat_input" Quote Link to comment https://forums.phpfreaks.com/topic/10421-php-form-validation/#findComment-38840 Share on other sites More sharing options...
Crimpage Posted May 25, 2006 Share Posted May 25, 2006 Thats alot of code...Quick point, when validating, you are asking:if($_POST["radiostations[]"]=="") {you don't need the [] because it is not the name of the variable. [] tells it that it will become the $_POST['radiostations'] variable.And i dont use double quotes in my $_POST[''] arrays... im not sure if it makes a difference.- CrimpageSee how that goes... Quote Link to comment https://forums.phpfreaks.com/topic/10421-php-form-validation/#findComment-38844 Share on other sites More sharing options...
byronrode Posted May 25, 2006 Author Share Posted May 25, 2006 [!--quoteo(post=376954:date=May 25 2006, 12:06 PM:name=Crimpage)--][div class=\'quotetop\']QUOTE(Crimpage @ May 25 2006, 12:06 PM) [snapback]376954[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thats alot of code...Quick point, when validating, you are asking:if($_POST["radiostations[]"]=="") {you don't need the [] because it is not the name of the variable. [] tells it that it will become the $_POST['radiostations'] variable.And i dont use double quotes in my $_POST[''] arrays... im not sure if it makes a difference.- CrimpageSee how that goes...[/quote]Nope, no luck. if i take the array [] out of the post's, when it validates, it fills in a checkbox with "array".Thanks for trying though Quote Link to comment https://forums.phpfreaks.com/topic/10421-php-form-validation/#findComment-38847 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.