ShadowIce Posted January 19, 2010 Share Posted January 19, 2010 How can I make this thing detect errors like it is supposed to? when u try to submit nothing or < or > the min & max values, it still lets u submit the form. it should catch the errors if not AT LEAST the f_name0001.. <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } function VerifyForm(&$values, &$errors) { // Do all necessary form verification if (strlen($values['f_name0001']) < 3){ $errors['f_name0001'] = '* Name too short'; }else if (strlen($values['f_name0001']) > 50){ $errors['f_name0001'] = '* Name too long'; } if ($values['f_name0001'] == ''){ $errors['f_name0001'] = '* Please fill in your name!'; } if (!(spamcheck($values['email']))){ $errors['email'] = '* Email address invalid'; } if(strlen($values['email']) == 0){ $errors['email'] = '* Please fill in your email!'; } if (strlen($values['text']) == 0) $errors['text'] = '* Text required'; return (count($errors) == 0); } function DisplayForm($values, $errors) { ?> <?php session_start(); ?><?php /*This code is for use on www.imageposeidon.com ONLY! Using this code without written permission from imageposeidon.com is a violation of the GNU Public License (GPL) And will be dealt with to the fullest extent of the law */ ?><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Image Poseidon</title> <LINK href="style.css" rel="stylesheet" type="text/css"> </head> <body> <?php if (count($errors) > 0){ $fontstart = "<font color=\"#FF0000\">"; $fontend = "</font>"; if(count($errors) > 1){echo "<p>".$fontstart."* There were ".count($errors)." errors in your submitted form, please correct them and try again.".$fontend."</p>"."\n";} if(count($errors) == 1){echo "<p>".$fontstart."* There is ".count($errors)." error in your submitted form, please correct it and try again.".$fontend."</p>"."\n";} } ?> <?php if (count($errors) > 0){ ?><tr> <?php if($errors['f_name0001'] != ''){ ?><td class="error"><?= $fontstart.$errors['f_name0001'].$fontend ?></td><br><?php } ?> <?php if($errors['email'] != ''){?><td class="error"><?= $fontstart.$errors['email'].$fontend ?></td><br><?php } ?> <?php if($errors['text'] != ''){?><td class="error"><?= $fontstart.$errors['text'].$fontend ?></td><br><?php } ?> </tr> <?php } ?> <script type="text/javascript" src="js/highlight-active-input.js"></script> <?php require('header.php'); ?> <FORM ACTION="page2.php" method=post> <center> <!--<fieldset> <legend>Image Poseidon Order Form</legend> --> <table> <tr> <td><label for="fname_0001">First Name: </label></td> <td><input class="textInput" type="text" name="f_name0001" maxlength="30" id="f_name0001" size="30" /></td> </tr> <tr> <td><label for="lname_0001">Last Name: </label></td> <td><input class="textInput" type="text" name="l_name0001" maxlength="30" id="l_name0001" size="30" /></td> </tr> <tr> <td><label for="a_d0001">Shipping Address: </label></td> <td><input class="textInput" type="text" name="ad_0001" maxlength="128" id="ad_0001" size="30" /></td> </tr> <tr> <td>Country: </td> <td><select onfocus="this.style.backgroundColor='#4D6DF3';" onblur="this.style.backgroundColor='';" class="textInput" id='countrySelect' name='co_0001' style="width: 209px;"> <option value="">Choose Country</option> <option value="Afganistan">Afghanistan</option> <option value="Albania">Albania</option> <option value="Algeria">Algeria</option> <option value="American Samoa">American Samoa</option> <option value="Andorra">Andorra</option> <option value="Angola">Angola</option> <option value="Anguilla">Anguilla</option> <option value="Antigua & Barbuda">Antigua & Barbuda</option> <option value="Argentina">Argentina</option> <option value="Armenia">Armenia</option> <option value="Aruba">Aruba</option> <option value="Australia">Australia</option> <option value="Austria">Austria</option> <option value="Azerbaijan">Azerbaijan</option> <option value="Bahamas">Bahamas</option> <option value="Bahrain">Bahrain</option> <option value="Bangladesh">Bangladesh</option> <option value="Barbados">Barbados</option> <option value="Belarus">Belarus</option> <option value="Belgium">Belgium</option> <option value="Belize">Belize</option> <option value="Benin">Benin</option> <option value="Bermuda">Bermuda</option> <option value="Bhutan">Bhutan</option> <option value="Bolivia">Bolivia</option> <option value="Bonaire">Bonaire</option> <option value="Bosnia & Herzegovina">Bosnia & Herzegovina</option> <option value="Botswana">Botswana</option> <option value="Brazil">Brazil</option> <option value="British Indian Ocean Ter">British Indian Ocean Ter</option> <option value="Brunei">Brunei</option> <option value="Bulgaria">Bulgaria</option> <option value="Burkina Faso">Burkina Faso</option> <option value="Burundi">Burundi</option> <option value="Cambodia">Cambodia</option> <option value="Cameroon">Cameroon</option> <option value="Canada">Canada</option> <option value="Canary Islands">Canary Islands</option> <option value="Cape Verde">Cape Verde</option> <option value="Cayman Islands">Cayman Islands</option> <option value="Central African Republic">Central African Republic</option> <option value="Chad">Chad</option> <option value="Channel Islands">Channel Islands</option> <option value="Chile">Chile</option> <option value="China">China</option> <option value="Christmas Island">Christmas Island</option> <option value="Cocos Island">Cocos Island</option> <option value="Colombia">Colombia</option> <option value="Comoros">Comoros</option> <option value="Congo">Congo</option> <option value="Cook Islands">Cook Islands</option> <option value="Costa Rica">Costa Rica</option> <option value="Cote DIvoire">Cote D'Ivoire</option> <option value="Croatia">Croatia</option> <option value="Cuba">Cuba</option> <option value="Curaco">Curacao</option> <option value="Cyprus">Cyprus</option> <option value="Czech Republic">Czech Republic</option> <option value="Denmark">Denmark</option> <option value="Djibouti">Djibouti</option> <option value="Dominica">Dominica</option> <option value="Dominican Republic">Dominican Republic</option> <option value="East Timor">East Timor</option> <option value="Ecuador">Ecuador</option> <option value="Egypt">Egypt</option> <option value="El Salvador">El Salvador</option> <option value="Equatorial Guinea">Equatorial Guinea</option> <option value="Eritrea">Eritrea</option> <option value="Estonia">Estonia</option> <option value="Ethiopia">Ethiopia</option> <option value="Falkland Islands">Falkland Islands</option> <option value="Faroe Islands">Faroe Islands</option> <option value="Fiji">Fiji</option> <option value="Finland">Finland</option> <option value="France">France</option> <option value="French Guiana">French Guiana</option> <option value="French Polynesia">French Polynesia</option> <option value="French Southern Ter">French Southern Ter</option> <option value="Gabon">Gabon</option> <option value="Gambia">Gambia</option> <option value="Georgia">Georgia</option> <option value="Germany">Germany</option> <option value="Ghana">Ghana</option> <option value="Gibraltar">Gibraltar</option> <option value="Great Britain">Great Britain</option> <option value="Greece">Greece</option> <option value="Greenland">Greenland</option> <option value="Grenada">Grenada</option> <option value="Guadeloupe">Guadeloupe</option> <option value="Guam">Guam</option> <option value="Guatemala">Guatemala</option> <option value="Guinea">Guinea</option> <option value="Guyana">Guyana</option> <option value="Haiti">Haiti</option> <option value="Hawaii">Hawaii</option> <option value="Honduras">Honduras</option> <option value="Hong Kong">Hong Kong</option> <option value="Hungary">Hungary</option> <option value="Iceland">Iceland</option> <option value="India">India</option> <option value="Indonesia">Indonesia</option> <option value="Iran">Iran</option> <option value="Iraq">Iraq</option> <option value="Ireland">Ireland</option> <option value="Isle of Man">Isle of Man</option> <option value="Israel">Israel</option> <option value="Italy">Italy</option> <option value="Jamaica">Jamaica</option> <option value="Japan">Japan</option> <option value="Jordan">Jordan</option> <option value="Kazakhstan">Kazakhstan</option> <option value="Kenya">Kenya</option> <option value="Kiribati">Kiribati</option> <option value="Korea North">Korea North</option> <option value="Korea Sout">Korea South</option> <option value="Kuwait">Kuwait</option> <option value="Kyrgyzstan">Kyrgyzstan</option> <option value="Laos">Laos</option> <option value="Latvia">Latvia</option> <option value="Lebanon">Lebanon</option> <option value="Lesotho">Lesotho</option> <option value="Liberia">Liberia</option> <option value="Libya">Libya</option> <option value="Liechtenstein">Liechtenstein</option> <option value="Lithuania">Lithuania</option> <option value="Luxembourg">Luxembourg</option> <option value="Macau">Macau</option> <option value="Macedonia">Macedonia</option> <option value="Madagascar">Madagascar</option> <option value="Malaysia">Malaysia</option> <option value="Malawi">Malawi</option> <option value="Maldives">Maldives</option> <option value="Mali">Mali</option> <option value="Malta">Malta</option> <option value="Marshall Islands">Marshall Islands</option> <option value="Martinique">Martinique</option> <option value="Mauritania">Mauritania</option> <option value="Mauritius">Mauritius</option> <option value="Mayotte">Mayotte</option> <option value="Mexico">Mexico</option> <option value="Midway Islands">Midway Islands</option> <option value="Moldova">Moldova</option> <option value="Monaco">Monaco</option> <option value="Mongolia">Mongolia</option> <option value="Montserrat">Montserrat</option> <option value="Morocco">Morocco</option> <option value="Mozambique">Mozambique</option> <option value="Myanmar">Myanmar</option> <option value="Nambia">Nambia</option> <option value="Nauru">Nauru</option> <option value="Nepal">Nepal</option> <option value="Netherland Antilles">Netherland Antilles</option> <option value="Netherlands">Netherlands (Holland, Europe)</option> <option value="Nevis">Nevis</option> <option value="New Caledonia">New Caledonia</option> <option value="New Zealand">New Zealand</option> <option value="Nicaragua">Nicaragua</option> <option value="Niger">Niger</option> <option value="Nigeria">Nigeria</option> <option value="Niue">Niue</option> <option value="Norfolk Island">Norfolk Island</option> <option value="Norway">Norway</option> <option value="Oman">Oman</option> <option value="Pakistan">Pakistan</option> <option value="Palau Island">Palau Island</option> <option value="Palestine">Palestine</option> <option value="Panama">Panama</option> <option value="Papua New Guinea">Papua New Guinea</option> <option value="Paraguay">Paraguay</option> <option value="Peru">Peru</option> <option value="Phillipines">Philippines</option> <option value="Pitcairn Island">Pitcairn Island</option> <option value="Poland">Poland</option> <option value="Portugal">Portugal</option> <option value="Puerto Rico">Puerto Rico</option> <option value="Qatar">Qatar</option> <option value="Republic of Montenegro">Republic of Montenegro</option> <option value="Republic of Serbia">Republic of Serbia</option> <option value="Reunion">Reunion</option> <option value="Romania">Romania</option> <option value="Russia">Russia</option> <option value="Rwanda">Rwanda</option> <option value="St Barthelemy">St Barthelemy</option> <option value="St Eustatius">St Eustatius</option> <option value="St Helena">St Helena</option> <option value="St Kitts-Nevis">St Kitts-Nevis</option> <option value="St Lucia">St Lucia</option> <option value="St Maarten">St Maarten</option> <option value="St Pierre & Miquelon">St Pierre & Miquelon</option> <option value="St Vincent & Grenadines">St Vincent & Grenadines</option> <option value="Saipan">Saipan</option> <option value="Samoa">Samoa</option> <option value="Samoa American">Samoa American</option> <option value="San Marino">San Marino</option> <option value="Sao Tome & Principe">Sao Tome & Principe</option> <option value="Saudi Arabia">Saudi Arabia</option> <option value="Senegal">Senegal</option> <option value="Seychelles">Seychelles</option> <option value="Sierra Leone">Sierra Leone</option> <option value="Singapore">Singapore</option> <option value="Slovakia">Slovakia</option> <option value="Slovenia">Slovenia</option> <option value="Solomon Islands">Solomon Islands</option> <option value="Somalia">Somalia</option> <option value="South Africa">South Africa</option> <option value="Spain">Spain</option> <option value="Sri Lanka">Sri Lanka</option> <option value="Sudan">Sudan</option> <option value="Suriname">Suriname</option> <option value="Swaziland">Swaziland</option> <option value="Sweden">Sweden</option> <option value="Switzerland">Switzerland</option> <option value="Syria">Syria</option> <option value="Tahiti">Tahiti</option> <option value="Taiwan">Taiwan</option> <option value="Tajikistan">Tajikistan</option> <option value="Tanzania">Tanzania</option> <option value="Thailand">Thailand</option> <option value="Togo">Togo</option> <option value="Tokelau">Tokelau</option> <option value="Tonga">Tonga</option> <option value="Trinidad & Tobago">Trinidad & Tobago</option> <option value="Tunisia">Tunisia</option> <option value="Turkey">Turkey</option> <option value="Turkmenistan">Turkmenistan</option> <option value="Turks & Caicos Is">Turks & Caicos Is</option> <option value="Tuvalu">Tuvalu</option> <option value="Uganda">Uganda</option> <option value="Ukraine">Ukraine</option> <option value="United Arab Erimates">United Arab Emirates</option> <option value="United Kingdom">United Kingdom</option> <option value="United States of America">United States of America</option> <option value="Uraguay">Uruguay</option> <option value="Uzbekistan">Uzbekistan</option> <option value="Vanuatu">Vanuatu</option> <option value="Vatican City State">Vatican City State</option> <option value="Venezuela">Venezuela</option> <option value="Vietnam">Vietnam</option> <option value="Virgin Islands (Brit)">Virgin Islands (Brit)</option> <option value="Virgin Islands (USA)">Virgin Islands (USA)</option> <option value="Wake Island">Wake Island</option> <option value="Wallis & Futana Is">Wallis & Futana Is</option> <option value="Yemen">Yemen</option> <option value="Zaire">Zaire</option> <option value="Zambia">Zambia</option> <option value="Zimbabwe">Zimbabwe</option> </select> </tr> <tr> <td><label for="c0001">City: </label></td> <td><input class="textInput" type="text" name="c_0001" maxlength="30" id="c_0001" size="30" /></td> </tr> <br><br> <tr> <td>State: </td> <td> <select onfocus="this.style.backgroundColor='#4D6DF3';" onblur="this.style.backgroundColor='';" class="textInput" name='sp_0001' id='stateSelect' name='state' style="width: 209px;"> <option selected value="">Choose State</option> <option value="">-- UNITED STATES --</option> <option value="Alabama">Alabama</option> <option value="Alaska">Alaska</option> <option value="Arizona">Arizona</option> <option value="Arkansas">Arkansas</option> <option value="California">California</option> <option value="Colorado">Colorado</option> <option value="Connecticut">Connecticut</option> <option value="Delaware">Delaware</option> <option value="Florida">Florida</option> <option value="Georgia">Georgia</option> <option value="Hawaii">Hawaii</option> <option value="Idaho">Idaho</option> <option value="Illinois">Illinois</option> <option value="Indiana">Indiana</option> <option value="Iowa">Iowa</option> <option value="Kansas">Kansas</option> <option value="Kentucky">Kentucky</option> <option value="Louisiana">Louisiana</option> <option value="Maine">Maine</option> <option value="Maryland">Maryland</option> <option value="Massachusetts">Massachusetts</option> <option value="Michigan">Michigan</option> <option value="Minnesota">Minnesota</option> <option value="Mississippi">Mississippi</option> <option value="Missouri">Missouri</option> <option value="Montana">Montana</option> <option value="Nebraska">Nebraska</option> <option value="Nevada">Nevada</option> <option value="New Hampshire">New Hampshire</option> <option value="New Jersey">New Jersey</option> <option value="New Mexico">New Mexico</option> <option value="New York">New York</option> <option value="North Carolina">North Carolina</option> <option value="North Dakota">North Dakota</option> <option value="Ohio">Ohio</option> <option value="Oklahoma">Oklahoma</option> <option value="Oregon">Oregon</option> <option value="Pennsylvania">Pennsylvania</option> <option value="Rhode Island">Rhode Island</option> <option value="South Carolina">South Carolina</option> <option value="South Dakota">South Dakota</option> <option value="Tennessee">Tennessee</option> <option value="Texas">Texas</option> <option value="Utah">Utah</option> <option value="Vermont">Vermont</option> <option value="Virginia">Virginia</option> <option value="Washington">Washington</option> <option value="West Virginia">West Virginia</option> <option value="Wisconsin">Wisconsin</option> <option value="Wyoming">Wyoming</option> <option value="">-- CANADA --</option> <option value="Alberta">Alberta</option> <option value="British Columbia">British Columbia</option> <option value="Manitoba">Manitoba</option> <option value="New Brunswick">New Brunswick</option> <option value="Newfoundland and Labrador">Newfoundland and Labrador</option> <option value="Northwest Territories">Northwest Territories</option> <option value="Nova Scotia">Nova Scotia</option> <option value="Nunavut">Nunavut</option> <option value="Ontario">Ontario</option> <option value="Prince Edward Island">Prince Edward Island</option> <option value="Quebec">Quebec</option> <option value="Saskatchewan">Saskatchewan</option> <option value="Yukon Territory">Yukon Territory</option> <option value="">-- AUSTRALIA --</option> <option value="Australian Capital Territory">Australian Capital Territory</option> <option value="New South Wales">New South Wales</option> <option value="Northern Territory">Northern Territory</option> <option value="Queensland">Queensland</option> <option value="South Australia">South Australia</option> <option value="Tasmania">Tasmania</option> <option value="Victoria">Victoria</option> <option value="Western Australia">Western Australia</option> </select> </td> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> <td width=150>Item: <br> </td> <td width=15>Quantity: <br> </td> </tr> <tr> <td>CD</td> <td><input class="textInput" type="text" name="qtycd_0001" value = "1" size="30" maxlength="7"></td> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> <td>Please enter a discount code if you have one: </td> <td><input class="textInput" type="text" name="sd_0001" value="000-000-00000" size="30" maxlength="64"></td> </tr> <tr align="center"> <td> <center> <input type = "submit" value="Go To Next Page"> </center> </td> </tr> </table> <!--</legend> </fieldset>--> </center> </form> <script type="text/javascript"> // Initialize the input highlight script initInputHighlightScript(); </script> </body> </html><?php } function ProcessForm($values) { //mail('$adminemail', 'Form test', $values['text'], "From: \"{$values['f_name0001']}\" <{$values['email']}>"); // Replace with actual page or redirect <!-- s:P --><img src=\"{SMILIES_PATH}/icon_razz.gif\" alt=\"\" title=\"Razz\" /><!-- s:P --> echo "<html>\n<head><title>Thank you!</title></head>\n<body>\nThank you!\n<br>\nYour data would have been submitted if this were a real form! =D\n<br>\n<a href=\"./formvalidation.php\">Go Back To Main Page</a>\n<br>\n</body>\n</html>"; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); // if (!VerifyForm($formValues, $formErrors)) if (!(VerifyForm($formValues, $formErrors)) || !(array_key_exists('f_name0001', $formValues))){ DisplayForm($formValues, $formErrors); }else{ ProcessForm($formValues); } }else{ DisplayForm(null, null); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/ Share on other sites More sharing options...
Adam Posted January 19, 2010 Share Posted January 19, 2010 Could you post just the relevant code? Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-997999 Share on other sites More sharing options...
ShadowIce Posted January 19, 2010 Author Share Posted January 19, 2010 well, here's what it's ORIGINALLY supposed to do as i ran this code through a test run: formvalidation.php: <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } function VerifyForm(&$values, &$errors) { // Do all necessary form verification if (strlen($values['name']) < 3){ $errors['name'] = '* Name too short'; }else if (strlen($values['name']) > 50){ $errors['name'] = '* Name too long'; } if ($values['name'] == ''){ $errors['name'] = '* Please fill in your name!'; } if (!(spamcheck($values['email']))){ $errors['email'] = '* Email address invalid'; } if(strlen($values['email']) == 0){ $errors['email'] = '* Please fill in your email!'; } if (strlen($values['text']) == 0) $errors['text'] = '* Text required'; return (count($errors) == 0); } function DisplayForm($values, $errors) { ?><html> <head><title>Yadda yadda</title></head> <body> <?php if (count($errors) > 0){ $fontstart = "<font color=\"#FF0000\">"; $fontend = "</font>"; if(count($errors) > 1){echo "<p>".$fontstart."* There were ".count($errors)." errors in your submitted form, please correct them and try again.".$fontend."</p>"."\n";} if(count($errors) == 1){echo "<p>".$fontstart."* There is ".count($errors)." error in your submitted form, please correct it and try again.".$fontend."</p>"."\n";} } ?> <?php if (count($errors) > 0){ ?><tr> <?php if($errors['name'] != ''){ ?><td class="error"><?= $fontstart.$errors['name'].$fontend ?></td><br><?php } ?> <?php if($errors['email'] != ''){?><td class="error"><?= $fontstart.$errors['email'].$fontend ?></td><br><?php } ?> <?php if($errors['text'] != ''){?><td class="error"><?= $fontstart.$errors['text'].$fontend ?></td><br><?php } ?> </tr> <?php } ?><form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST"> <table> <tr> <td>Name:</td> <td><input type="text" size="30" name="name" value="<?= htmlentities($values['name']) ?>"/> </tr> <tr> <td>Email:</td> <td><input type="text" size="30" name="email" value="<?= htmlentities($values['email']) ?>"/> </tr> <tr> <td valign="top">Text:</td> <td> <textarea name="text" cols="30" rows="6"><?= htmlentities($values['text']) ?></textarea> </td> </tr> <tr><td colspan="2" align="center"><input type="submit" value="Submit"></tr> </table> </form> </body> </html><?php } function ProcessForm($values) { //mail('$adminemail', 'Form test', $values['text'], "From: \"{$values['name']}\" <{$values['email']}>"); echo "<html>\n<head><title>Thank you!</title></head>\n<body>\nThank you!\n<br>\nYour data would have been submitted if this were a real form! =D\n<br>\n<a href=\"./formvalidation.php\">Go Back To Main Page</a>\n<br>\n</body>\n</html>"; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); // if (!VerifyForm($formValues, $formErrors)) if (!(VerifyForm($formValues, $formErrors)) || !(array_key_exists('name', $formValues))){ DisplayForm($formValues, $formErrors); }else{ ProcessForm($formValues); } }else{ DisplayForm(null, null); } ?> That's the ONLY relevant code. My WHOLE orderform.php IS the relevant code. I just need to know why it is not showing errors when I submit AT all.... Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998002 Share on other sites More sharing options...
Adam Posted January 19, 2010 Share Posted January 19, 2010 Think this is your problem: return (count($errors) == 0); Try just: return count($errors); Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998013 Share on other sites More sharing options...
ShadowIce Posted January 19, 2010 Author Share Posted January 19, 2010 didnt work Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998016 Share on other sites More sharing options...
Adam Posted January 19, 2010 Share Posted January 19, 2010 There's several problems then. Keep that last bit as what I just said or the VerifyForm() function will always return 0. I can only think there's a problem with your form logic, try a var_dump on the $errors array just before you return it. Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998023 Share on other sites More sharing options...
ShadowIce Posted January 19, 2010 Author Share Posted January 19, 2010 it didnt return anything.. function VerifyForm(&$values, &$errors) { // Do all necessary form verification if (strlen($values['f_name0001']) < 3){ $errors['f_name0001'] = '* Name too short'; }else if (strlen($values['f_name0001']) > 50){ $errors['f_name0001'] = '* Name too long'; } if ($values['f_name0001'] == ''){ $errors['f_name0001'] = '* Please fill in your name!'; } if (!(spamcheck($values['email']))){ $errors['email'] = '* Email address invalid'; } if(strlen($values['email']) == 0){ $errors['email'] = '* Please fill in your email!'; } if (strlen($values['text']) == 0) $errors['text'] = '* Text required'; echo "Var dump: ".var_dump($errors)."<br>\n"; return count($errors); } function DisplayForm($values, $errors) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998027 Share on other sites More sharing options...
Adam Posted January 19, 2010 Share Posted January 19, 2010 By nothing do you mean "bool(false)"? Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998029 Share on other sites More sharing options...
ShadowIce Posted January 19, 2010 Author Share Posted January 19, 2010 no. I mean it didnt print ANYTHING to the screen.. Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998031 Share on other sites More sharing options...
Buddski Posted January 19, 2010 Share Posted January 19, 2010 What is the name of this file? I noticed your form action is pointing to page2.php.. Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998033 Share on other sites More sharing options...
ShadowIce Posted January 19, 2010 Author Share Posted January 19, 2010 if u mean what is the name of this file, then it is Orderform.php, if u mean page2.php, then heres page2.php: <?php session_start(); ?> <?php require('header.php'); require('taxheader.php'); require('sessionvars.php'); ?><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Image Poseidon</title> </head> <body> <LINK href="style.css" rel="stylesheet" type="text/css"> <script src="view_printable.js"></script> <script src="mainscripts.js"></script> <center> <a href="#" onclick="javascript:view_printable();">Click For Printable Page</a><br> </center> <center> <h2>This is your order so far: </h2> </center> <FORM name="f0001" id="f0001" ACTION="processorder.php" method=post> <center> <?php echo "Name: <b><u>".$_SESSION['f_name0001']." ".$_SESSION['l_name0001']."</u></b><br>\n" ."Address: <b><u>".$_SESSION['ad_0001']."</u></b><br>\n" ."Country: <b><u>".$_SESSION['co_0001']."</u></b><br>\n" ."City: <b><u>".$_SESSION['c_0001']."</u></b><br>\n" ."State/Province: <b><u>".$_SESSION['sp_0001']."</u></b><br>\n" ."Amount of CD(s) you want to purchase: <b><u>".$_SESSION['qtycd_0001']."</u></b><br>\n"; if($_SESSION['hasadiscount'] == true){echo "Your coupon code: <b><u>".$_SESSION['customercouponcode']."</u></b><br><br>\n";} echo "<img src=\"gradient_grey3596386127_footer-iaza.png\"></img><br>\n"; if($_SESSION['hasadiscount'] == true){ echo "<br>Original Total: <br><br>\n" ."<b>".$_SESSION['istotal']."-"."10%"."</b>"."<br>\n" ."<br>Your total: <br><br>\n" ."<b>".$_SESSION['isdiscounttotal']."</b><br>\n"; }else if($_SESSION['hasadiscount'] == false){ echo "<br>Your Total: <br><br>\n" ."<b>".$_SESSION['istotal']."</b><br>\n"; } echo "<br>\n"; echo "<img src=\"gradient_grey3596386127-iaza.png\"></img>\n"; ?> <br> <a href="#" onclick="javascript:view_printable();">Click For Printable Page</a><br><br> <input name="subt1" id="subt1" type="submit" value="Submit" onclick="FormControl(1);"> </center> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998037 Share on other sites More sharing options...
ShadowIce Posted January 19, 2010 Author Share Posted January 19, 2010 Ok, I found the problem. It's because I'm linking it to another page. how can I stop it from linking to page2.php UNLESS all required forms are filled out, and they are filled out correctly? Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998044 Share on other sites More sharing options...
Buddski Posted January 19, 2010 Share Posted January 19, 2010 Get it to link back to itself, validate the form, if its ok header location them to the next page (or something) otherwise, fill out the form with their already entered data and give them an error message.. Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998047 Share on other sites More sharing options...
Adam Posted January 19, 2010 Share Posted January 19, 2010 *slaps forehead* That'll be why var_dump had no output. Nice spot Buddski! You just need to change the form action as Buddski was talking about. Change: <FORM ACTION="page2.php" method=post> To: <form action="Orderform.php" method="post"> You also need to re-think the way you're testing if the form validation was successful. if (!(VerifyForm($formValues, $formErrors)) [...] Returning the $error array length will lead to this evaluating to true when the function returns 0 errors, because 0 == false. Instead return from the VerifyForm() function like this: if (count($errors) > 0) { return false; } return true; Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998063 Share on other sites More sharing options...
ShadowIce Posted January 19, 2010 Author Share Posted January 19, 2010 OMG! U guys are GENIUSES! it worked! =D Btw. var_dump returned: array(2) { ["email"]=> string(28) "* Please fill in your email!" ["text"]=> string(15) "* Text required" } Var dump: Quote Link to comment https://forums.phpfreaks.com/topic/189022-please-help-order-form-not-alerting-user-if-they-have-error/#findComment-998066 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.