Jump to content

Help Required


Scoopsowl

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;}}}}}}

 

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.