ShadowIce Posted January 18, 2010 Share Posted January 18, 2010 After entering the form data correctly, and when I click the 'Go Back To Main Page' link, how can I make it so that it doesn't display the error(s) again? formvalidation.php: <?php session_start(); ?> <?php function VerifyForm(&$values, &$errors) { // Do all necessary form verification if (strlen($values['name']) < 3) $errors['name'] = '* Name too short'; elseif (strlen($values['name']) > 50) $errors['name'] = '* Name too long'; // Needs better checking if (!ereg('.*@.*\..{2,4}', $values['email'])) $errors['email'] = '* Email address invalid'; 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>"; echo $fontstart."<p>There were some errors in your submitted form, please correct them and try again.</p>".$fontend; ?> <tr> <td class="error"><?= $fontstart.$errors['name'].$fontend ?></td><br> <td class="error"><?= $fontstart.$errors['email'].$fontend ?></td><br> <td class="error"><?= $fontstart.$errors['text'].$fontend ?></td><br> </tr> <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']}>"); // Replace with actual page or redirect 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)) DisplayForm($formValues, $formErrors); else ProcessForm($formValues); } else DisplayForm(null, null); ?> Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/ Share on other sites More sharing options...
phonydream Posted January 18, 2010 Share Posted January 18, 2010 Try: if (!(VerifyForm($formValues, $formErrors)) || array_key_exists('name', $formValues))) Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997625 Share on other sites More sharing options...
ShadowIce Posted January 18, 2010 Author Share Posted January 18, 2010 Where? Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997635 Share on other sites More sharing options...
ShadowIce Posted January 18, 2010 Author Share Posted January 18, 2010 nvm. it didnt work right >< Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997644 Share on other sites More sharing options...
phonydream Posted January 18, 2010 Share Posted January 18, 2010 Try if (!(VerifyForm($formValues, $formErrors)) || !(array_key_exists('name', $formValues))) Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997645 Share on other sites More sharing options...
ShadowIce Posted January 18, 2010 Author Share Posted January 18, 2010 Didnt work.. Here's what I have: function ProcessForm($values) { //mail('$adminemail', 'Form test', $values['text'], "From: \"{$values['name']}\" <{$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('name', $formValues))){ DisplayForm($formValues, $formErrors); }else{ ProcessForm($formValues); } } // else{ // DisplayForm(null, null); // } Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997651 Share on other sites More sharing options...
phonydream Posted January 18, 2010 Share Posted January 18, 2010 Can you post the URL? Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997664 Share on other sites More sharing options...
ShadowIce Posted January 18, 2010 Author Share Posted January 18, 2010 Check your PM's, phonydream Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997667 Share on other sites More sharing options...
ShadowIce Posted January 18, 2010 Author Share Posted January 18, 2010 Case: Closed! Problem Solved! Thanks to phony's help, I have solved this problem! =D Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997697 Share on other sites More sharing options...
Maq Posted January 18, 2010 Share Posted January 18, 2010 Case: Closed! Problem Solved! Thanks to phony's help, I have solved this problem! =D Glad to hear everything is working. Please mark as solved by clicking the self titled button in the bottom left. Link to comment https://forums.phpfreaks.com/topic/188935-form-validation-error-glitch-oo/#findComment-997702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.