I am a PHP newbie. My employer wants an email newsletter signup on our website. I built the form, but it is not validating. I got the script from my server, Host Gator. The script works for posting, but if you leave off the name or email, it just takes you to a blank white page.
I've never seen a form validated with the unset($_GET['do']);
here is the script: (I apologize if code entered here incorrectly. I could not find how to enter php code.)
<?php
switch (@$_GET['do'])
{
case "send":
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$femail = $_POST['femail'];
$fsendmail = $_POST['fsendmail'];
$secretinfo = $_POST['info'];
if (!preg_match("/\S+/",$fname))
{
unset($_GET['do']);
$message = "First Name required. Please try again.";
break;
}
if (!preg_match("/\S+/",$lname))
{
unset($_GET['do']);
$message = "Last Name required. Please try again.";
break;
}
if (!preg_match("/^\S+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,6}$/",$femail))
{
unset($_GET['do']);
$message = "Primary Email Address is incorrect. Please try again.";
break;
}
if ($secretinfo == "")
{
$myemail = "newsletter@washingtoncountysheriffwi.org";
$emess = "First Name: ".$fname."\n";
$emess.= "Last Name: ".$lname."\n";
$emess.= "Email: ".$femail."\n";
$emess.= "Comments: ".$fsendmail;
$ehead = "From: ".$femail."\r\n";
$subj = "An Email from ".$fname." ".$lname."!";
$mailsend=mail("$myemail","$subj","$emess","$ehead");
$message = "Email was sent.";
}
unset($_GET['do']);
header("Location: thankyounews.html");
break;
default: break;
}
?>
The form works, but if name or email is omitted, it goes to blank page instead of error notification.
Thanks for your help.
Helen:confused: