
Originally Posted by
itskater
Thank you guys,
Is there anyway to use a different code then exit? If I use echo then exit it shows the echo notice event if it was successful. How can I make it show the failure notice?
PHP Code:
$userEmail = filter_var( $_POST['email'],FILTER_VALIDATE_EMAIL );
echo 'Were sorry, something went wrong.
Please go back.';
if( ! $userEmail ){
exit;
}
The notice needs to be in the same block as the exit command - after all, you only want to tell them "something went wrong" if something went wrong.
PHP Code:
$userEmail = filter_var( $_POST['email'],FILTER_VALIDATE_EMAIL );
if( ! $userEmail ){
// something went wrong.
// tell the user.
echo 'Were sorry, something went wrong.
Please go back.';
// make the script end here.
exit;
}
I would suggest something more useful than "Please go back" - send them to an actual error page, for example, or show them the form again (with error message(s) included). It's a little more complicated to set up, but it's a lot nicer for all concerned.
For example:
PHP Code:
if( ! $userEmail ){
header( "Location: http://example.com/contact-page-with-error-message.php" );
exit;
}
Bookmarks