Russia Posted December 10, 2009 Share Posted December 10, 2009 I would also like to add a email validation to it. How would I go about doing that without messing up the coding? So basically even if the whole form is filled out, and the email is in the wrong format, then do the same thing as when the form isn't totally filled out. If the email is in the correct format but the whole form isnt filled out, then show an error message, I already have all that coded in, exept the email validation. Can someone add that to my code? <?php $form = '<form action="" method="POST"> Email Address: <input size="40" type="text" value="' . $_POST["email_address"] . '" name="email_address"><br> Username <input size="40" type="text" value="' . $_POST["username"] . '" name="username"><br> password <input size="40" value="' . $_POST["password"] . '" type="text" name="password"><br> <input id="submit" class="submit-button" type="submit" name="submit" value="Reset Password" > </form>'; if (isset($_POST['submit'])) { $blank_inputs = 0; $test_array = array_count_values($_POST); $blank_inputs = $test_array[""]; if ($blank_inputs > 0) { //display an error message and put the form back up for editing echo "Please fill out the whole form.<hr>"; echo $form; } else { echo 'message sent'; } } else { echo $form; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/ Share on other sites More sharing options...
Russia Posted December 10, 2009 Author Share Posted December 10, 2009 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975119 Share on other sites More sharing options...
RussellReal Posted December 10, 2009 Share Posted December 10, 2009 You mean email activation.. like you send an email to them.. they click a link and their account is active? Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975122 Share on other sites More sharing options...
Russia Posted December 10, 2009 Author Share Posted December 10, 2009 No, to see if its in the correct format. Something like: ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email); But where would I add that? Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975123 Share on other sites More sharing options...
Russia Posted December 11, 2009 Author Share Posted December 11, 2009 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975153 Share on other sites More sharing options...
RussellReal Posted December 11, 2009 Share Posted December 11, 2009 if (($blank_inputs > 0) || (preg_match("/^[a-z0-9._-]+?@[a-z0-9-]+?(?:\.[a-z]{1,4}){1,2}$/i",$_POST['email']))) { //display an error message and put the form back up for editing echo "Please fill out the whole form.<hr>"; echo $form; } else { echo 'message sent'; } Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975237 Share on other sites More sharing options...
Russia Posted December 11, 2009 Author Share Posted December 11, 2009 So something like this? <?php $email = $_POST['email_address']; $form = '<form action="" method="POST"> Email Address: <input size="40" type="text" value="' . $_POST["email_address"] . '" name="email_address"><br> Username <input size="40" type="text" value="' . $_POST["username"] . '" name="username"><br> password <input size="40" value="' . $_POST["password"] . '" type="text" name="password"><br> <input id="submit" class="submit-button" type="submit" name="submit" value="Reset Password" > </form>'; if (isset($_POST['submit'])) { $blank_inputs = 0; $test_array = array_count_values($_POST); $blank_inputs = $test_array[""]; if (($blank_inputs > 0) || (preg_match("/^[a-z0-9._-]+?@[a-z0-9-]+?(?:\.[a-z]{1,4}){1,2}$/i",$_POST['email']))) { //display an error message and put the form back up for editing echo "Please fill out the whole form.<hr>"; echo $form; } else { echo 'message sent'; } } else { echo $form; } ?> Also, what does || mean in php? Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975378 Share on other sites More sharing options...
SamW Posted December 11, 2009 Share Posted December 11, 2009 Also, what does || mean in php? I believe it is the same as &&; it means and. Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975380 Share on other sites More sharing options...
Russia Posted December 11, 2009 Author Share Posted December 11, 2009 So what does && mean in php? Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975388 Share on other sites More sharing options...
SamW Posted December 11, 2009 Share Posted December 11, 2009 So what does && mean in php? The same as ||. Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975390 Share on other sites More sharing options...
mrMarcus Posted December 11, 2009 Share Posted December 11, 2009 they are not the same: Logical Operators Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975394 Share on other sites More sharing options...
oni-kun Posted December 11, 2009 Share Posted December 11, 2009 So what does && mean in php? The same as ||. Nope. 3 || 4, OR. 3 && 3, AND. So I'd recommend switching the || to an AND unless you want zero-length e-mails to boot. Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975407 Share on other sites More sharing options...
RussellReal Posted December 11, 2009 Share Posted December 11, 2009 So what does && mean in php? The same as ||. Nope. 3 || 4, OR. 3 && 3, AND. So I'd recommend switching the || to an AND unless you want zero-length e-mails to boot. yeah sorry.. I meant && <33 Quote Link to comment https://forums.phpfreaks.com/topic/184708-adding-email-validation/#findComment-975416 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.