TheJoey Posted September 4, 2009 Share Posted September 4, 2009 It just not validating anything. Im not good at all with regex but ive gotten this snip of the internet. Its not displaying errors. <?php // Function to display form function showForm($errorName=false,$errorEmail=false,$errorMesg=false){ if ($errorName) $errorTextName = "Please enter your name!"; if ($errorEmail) $errorTextEmail = "Please enter a valid email address!"; if ($errorMesg) $errorTextMesg = "Please leave a longer message!"; echo '<form action="form.php" method="POST"><table>'; // Display name field an error if needed echo '<tr><td>Name:</td><td><input type="text" name="name"></td></tr>'; if ($errorName) echo "<tr><td colspan='2'>$errorTextName</td></tr>"; // Display email field an error if needed echo '<tr><td>Email:</td><td><input type="text" name="email"></td></tr>'; if ($errorEmail) echo "<tr><td colspan='2'>$errorTextEmail</td></tr>"; // Display message field an error if needed echo '<tr><td>Message:</td><td><textarea name="mesg"></textarea></td></tr>'; if ($errorMesg) echo "<tr><td colspan='2'>$errorTextMesg</td></tr>"; echo '<tr><td><input type="submit" name="SubmitForm" value="Send"></td></tr>'; echo '<form>'; } if (!isset($_POST['SubmitForm'])) { showForm(); } else { //Init error variables $errorName = false; $errorEmail = false; $errorMesg = false; $name = isset($_POST['name']) ? trim($_POST['name']) : ''; $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $mesg = isset($_POST['mesg']) ? trim($_POST['mesg']) : ''; if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) $errorEmail = true; if (strlen($name)<3) $errorName = true; if (strlen($mesg)<10) $errorMesg = true; // Display the form again as there was an error if ($errorName || $errorEmail || $errorMesg) { showForm($errorName,$errorEmail,$errorMesg); } else { echo 'Submission was success!'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173058-solved-form-validation/ Share on other sites More sharing options...
sKunKbad Posted September 4, 2009 Share Posted September 4, 2009 So, what's your question? If you want to have good validation, why not try formmail from tectite.com Quote Link to comment https://forums.phpfreaks.com/topic/173058-solved-form-validation/#findComment-912155 Share on other sites More sharing options...
xangelo Posted September 4, 2009 Share Posted September 4, 2009 So, what's your question? If you want to have good validation, why not try formmail from tectite.com His problem was this: Its not displaying errors. I looked through the code and tested it out and it worked perfectly for me. Sorry TheJoey, I'm just not seeing any problems. Quote Link to comment https://forums.phpfreaks.com/topic/173058-solved-form-validation/#findComment-912166 Share on other sites More sharing options...
TheJoey Posted September 4, 2009 Author Share Posted September 4, 2009 there arent any problems, but it isnt validating. @ is being accepted as proper email whereas it should be name@mail.com there arent any syntax errors, its just not doing what its meant to. Quote Link to comment https://forums.phpfreaks.com/topic/173058-solved-form-validation/#findComment-912226 Share on other sites More sharing options...
TheJoey Posted September 4, 2009 Author Share Posted September 4, 2009 sorry i posted the wrong code, i seemed to have lost the one i needed questions with. Quote Link to comment https://forums.phpfreaks.com/topic/173058-solved-form-validation/#findComment-912228 Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 If you find it, please post.. otherwise please mark this topic as "solved". Quote Link to comment https://forums.phpfreaks.com/topic/173058-solved-form-validation/#findComment-912235 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.