harkly Posted February 2, 2010 Share Posted February 2, 2010 I am setting up an email confirmation page that will check the format of the entered info and print out any errors. If everything is ok it will send a confirmation email. My question is - How do I get it to run the checks and print out the form so that it can be corrected and then process the second part - sending the confirmation? I think I need to have an IF ELSE statement but not sure what it would be. // I think I need and IF here if (strlen($userID)<4 || strlen($userID)>32) { echo "Your User ID must be between 6 and 32 characters.<br>"; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "<font color=red> Invalid email</font> <br>\n"; } if ($pswd !== $pwd2) { echo "Passwords to not match, please re-enter.<br>"; } if (strlen($pswd)<6 || strlen($pswd)>32) { echo "Your password must be between 6 and 32 characters.<br>"; } $sql_check = mysql_query("select email from user where email='".$email."'") or die(mysql_error()); if (mysql_num_rows($sql_check)) { echo "<font color='red'>The e-mail ".$email." is already in use.</font> \n"; } echo " <form method='post' action='confirm_email.php' name='mailcheck' id='form_id' onSubmit=\"return (checkForm(this) && false);\"> <table width='700' border='0'> <tr> <td width='200'><div align='right'>userID: </div></td> <td width='100'><input id='userID' size='20' type='text' name='userID' value='$userID'></td> <td width='400' align='left'><div id='status'></div></td> </tr> <tr> <td width='200'><div align='right'>email: </div></td> <td width='100'><input id='email' size='20' type='text' name='email' value='$email'></td> <td width='400' align='left'><div id='status2'></div></td> </tr> <tr> <td width='200'><div align='right'>Password: </div></td> <td width='100'><input size='20' type='password' name='pswd'></td> <td width='400' align='left'><div id='status'></div></td> </tr> <tr> <td width='200'><div align='right'>Confirm Password: </div></td> <td width='100'><input size='20' type='password' name='pwd2'></td> <td width='400' align='left'><div id='status'></div></td> </tr> </table> <span class='button'> <input type='image' value='Add New Account' src='img/button_add.gif' width='64' height='25' onmouseover='javascript:this.src='img/button_add2.gif';' onmouseout='javascript:this.src='img/button_add.gif';'> </span> </form> "; //Then an ELSE here $sql = "INSERT INTO temp (userID, email, pswd, currentDate, confirmDate, confirm) VALUES ('$_POST[userID]','$_POST[email]','$_POST[pswd]',NOW(),'$_POST[confirmDate]','$_POST[confirm]')"; $result = mysql_query($sql) or die(mysql_error()); //These are the variables for the email $to = $_POST['email']; // this is the email address collected form the form $subject = "email confirmation"; // Subject $message = "Thank you for registering, please click on the link below to activate your account http://www.test.net/test/updateUser.php?uid=$userID&activate=1" ; $header = "From: [email protected]\r\n"; $header .= "Reply-to: [email protected]\r\n"; // This is the function to send the email if (mail($to, $subject, $message, $header)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } Just a note: I am verifying this info with javascript but in case it is turned off this is my backup. Link to comment https://forums.phpfreaks.com/topic/190709-php-if-statement-needed/ Share on other sites More sharing options...
jamkelvl Posted February 2, 2010 Share Posted February 2, 2010 First of all, you should have your form and processing of form and e-mailing of form all done on the same page. I believe this would be easiest. So basically, what you want to do is if the form data all validates then e-mail the form data? Something like... <?php if ($_POST['addNew'] == true) { //your code to validate form data goes here // if data is all validated, i think you said you did this with javascript // e-mail form // else form is already displayed below and you can // highlight errors if you'd like.. // all depends on how you're doing things } else { // display error message telling user to correct form data } ?> <form action="form.php" method="post"> <input type="hidden" name="formSent" value="true" /> <label for="input">Input:<label> <input type="text" name="input" value="<?php echo $_POST['input']; ?>" /> <input type="submit" value="Submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/190709-php-if-statement-needed/#findComment-1005757 Share on other sites More sharing options...
harkly Posted February 2, 2010 Author Share Posted February 2, 2010 I've tried something like this and this will not give me any errors is the form is incorrect, it goes directly to emailing the form. Link to comment https://forums.phpfreaks.com/topic/190709-php-if-statement-needed/#findComment-1005812 Share on other sites More sharing options...
harkly Posted February 3, 2010 Author Share Posted February 3, 2010 First of all, you should have your form and processing of form and e-mailing of form all done on the same page. I believe this would be easiest. I do I go about having the form on the same page as the processing? I have it working so that the form shows up on the processed page with any errors, but can't figure out how to get it to start blank - with no errors. Link to comment https://forums.phpfreaks.com/topic/190709-php-if-statement-needed/#findComment-1006227 Share on other sites More sharing options...
harkly Posted February 3, 2010 Author Share Posted February 3, 2010 I do I go about having the form on the same page as the processing? I have it working so that the form shows up on the processed page with any errors, but can't figure out how to get it to start blank - with no errors. That's How do I go about.... Link to comment https://forums.phpfreaks.com/topic/190709-php-if-statement-needed/#findComment-1006233 Share on other sites More sharing options...
jamkelvl Posted February 16, 2010 Share Posted February 16, 2010 Can I see your code? Link to comment https://forums.phpfreaks.com/topic/190709-php-if-statement-needed/#findComment-1012960 Share on other sites More sharing options...
idontkno Posted February 16, 2010 Share Posted February 16, 2010 If you want to put a validater, use your submit button. In otherwords, add a name to the input on the form. if (!isset($_POST['submit'])) { //validate } else { //error } As for your script emailing if its still wrong, that's because you haven't terminated the script. Link to comment https://forums.phpfreaks.com/topic/190709-php-if-statement-needed/#findComment-1012981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.