Scoopsowl Posted December 31, 2012 Share Posted December 31, 2012 Hi, I am new to php programming but found a script that checks email validation. The script works fine but instead of displaying the error message "Email address is invalid" I would like the script to go to an error page that I have designed. Below is a section of the script I am using. Any ideas? stristr($_REQUESTemail," ")){$errors[] = "Email address is invalid";}else{$ Thanks Quote Link to comment https://forums.phpfreaks.com/topic/272548-help-required/ Share on other sites More sharing options...
cpd Posted December 31, 2012 Share Posted December 31, 2012 You can redirect from there using the header("Location: ...") function but without seeing the rest of the script no-one can tell you if its a good idea or not as additional logic may be carried out after that if statement. Quote Link to comment https://forums.phpfreaks.com/topic/272548-help-required/#findComment-1402379 Share on other sites More sharing options...
Jessica Posted December 31, 2012 Share Posted December 31, 2012 Don't forget to call die() after the header. Quote Link to comment https://forums.phpfreaks.com/topic/272548-help-required/#findComment-1402382 Share on other sites More sharing options...
Scoopsowl Posted December 31, 2012 Author Share Posted December 31, 2012 Thanks for the quick replies. Please find below the expanded code. Once again..many thanks // Validate email field. if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { $_REQUEST['email'] = trim($_REQUEST['email']); if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ") || stristr($_REQUEST['email'],"\\") || stristr($_REQUEST['email'],":")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} } Quote Link to comment https://forums.phpfreaks.com/topic/272548-help-required/#findComment-1402389 Share on other sites More sharing options...
Christian F. Posted December 31, 2012 Share Posted December 31, 2012 First off: Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read. Thank you. Secondly: You shouldn't redirect the user upon a validation error, which an invalid/missing e-mail address is. What you should do is repopulate the form with the input from the user, add an error message telling what's wrong, and then show the form anew. Only after the input has been validated, and processed properly (in this case, e-mailed) should you redirect the user. Doing so to prevent a refresh of the page to re-submit the data, and thus preventing an erroneous duplication of said data. Quote Link to comment https://forums.phpfreaks.com/topic/272548-help-required/#findComment-1402423 Share on other sites More sharing options...
Jessica Posted December 31, 2012 Share Posted December 31, 2012 That code wouldn't be readable with code tags anyway. OP: Click the toggle button in the top left of the text editor to get to plain text and copy and paste your code in there to preserve the formatting. Quote Link to comment https://forums.phpfreaks.com/topic/272548-help-required/#findComment-1402429 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.