ramboangel11
06-01-2011, 05:09 AM
I have searched all over for the solution to my problem!
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
if(isset($_POST['Submit'])){
$myemail = "myemail@email.com";
$subject = "Update Resident Information";
$name = check_input($_POST['name'], "Enter your name");
$address = check_input($_POST['address'], "Enter your address");
$city = check_input($_POST['city'], "Enter your city");
$state = check_input($_POST['state'], "Enter your state");
$zip = check_input($_POST['zip'], "Enter your zip");
$home = check_input($_POST['home'], "Enter your home phone number");
$work = check_input($_POST['work'], "Enter your work phone number");
$mobile = check_input($_POST['mobile'], "Enter your mobile phone number");
$email = check_input($_POST['email'], "Enter your email address");
$emergname = check_input($_POST['emergname']);
$emergaddress = check_input($_POST['emergaddress']);
$emergcity = check_input($_POST['emergcity']);
$emergstate = check_input($_POST['emergstate']);
$emergzip = check_input($_POST['emergzip']);
$emerghome = check_input($_POST['emerghome']);
$emergwork = check_input($_POST['emergwork']);
$emergmobile = check_input($_POST['emergmobile']);
$emergemail = check_input($_POST['emergemail']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$message = "Hello!
An update to resident information has been received from:
Your Information
Name: $name
Address: $address
City: $city
State: $state
Zip: $zip
Home Phone Number: $home
Work Phone Number: $work
Mobile Phone Number: $mobile
Email Address: $email
Emergency Contact Information
Name: $emergname
Address: $emergaddress
City: $emergcity
State: $emergstate
Zip: $emergzip
Home Phone Number: $emerghome
Work Phone Number: $emergwork
Mobile Phone Number: $emergmobile
Email Address: $emergemail
";
mail($myemail, $subject, $message);
}
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
Then I echo $myError in my content. It returns the error that is listed, ie Enter your name, yet it still sends an email with the required fields as blank. How can I make this not send the email until all required fields are filled out?
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
if(isset($_POST['Submit'])){
$myemail = "myemail@email.com";
$subject = "Update Resident Information";
$name = check_input($_POST['name'], "Enter your name");
$address = check_input($_POST['address'], "Enter your address");
$city = check_input($_POST['city'], "Enter your city");
$state = check_input($_POST['state'], "Enter your state");
$zip = check_input($_POST['zip'], "Enter your zip");
$home = check_input($_POST['home'], "Enter your home phone number");
$work = check_input($_POST['work'], "Enter your work phone number");
$mobile = check_input($_POST['mobile'], "Enter your mobile phone number");
$email = check_input($_POST['email'], "Enter your email address");
$emergname = check_input($_POST['emergname']);
$emergaddress = check_input($_POST['emergaddress']);
$emergcity = check_input($_POST['emergcity']);
$emergstate = check_input($_POST['emergstate']);
$emergzip = check_input($_POST['emergzip']);
$emerghome = check_input($_POST['emerghome']);
$emergwork = check_input($_POST['emergwork']);
$emergmobile = check_input($_POST['emergmobile']);
$emergemail = check_input($_POST['emergemail']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$message = "Hello!
An update to resident information has been received from:
Your Information
Name: $name
Address: $address
City: $city
State: $state
Zip: $zip
Home Phone Number: $home
Work Phone Number: $work
Mobile Phone Number: $mobile
Email Address: $email
Emergency Contact Information
Name: $emergname
Address: $emergaddress
City: $emergcity
State: $emergstate
Zip: $emergzip
Home Phone Number: $emerghome
Work Phone Number: $emergwork
Mobile Phone Number: $emergmobile
Email Address: $emergemail
";
mail($myemail, $subject, $message);
}
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
Then I echo $myError in my content. It returns the error that is listed, ie Enter your name, yet it still sends an email with the required fields as blank. How can I make this not send the email until all required fields are filled out?