Forum Moderators: coopster
if(!$error_msg ¦¦!$error_msg1 ¦¦$error_msg2)
{
# if everything ok,
# define variables from the posted data
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$suggestion = $_POST ['suggestion'];
$messagetype = $_POST['messagetype'];
header("Location: thankyou.php");
}
#############################
But pipe does not work or do as I want so i am still stuck
pat
if( extract($_POST) ) {
$errmsg = "";
if(!isset($name) ) {
$errmsg .= "<p>Please Fill in the Name field</p>"
}
if(!isset($email) ) {
$errmsg .= "<p>Please fill in the email field</p>"
}
if(!isset($suggestion) ) {
$errmsg .= "<p>Please fill in your comments</p>"
}
if( $errmsg!= "" ) {
header("Location: thankyou.php");
} else {
echo $errmsg;
}
}
Honestly it would be more effecient to do this type of error checking with javascript instead. I've got a function for that if you are interested.
global $errmsg;
if( extract($_POST) ) {
if( $name == "" ) {
$errmsg["name"] = "<p>Please Fill in the Name field</p>";
}
if( $email == "" ) {
$errmsg["email"] = "<p>Please fill in the email field</p>";
}
if( $suggestion == "" ) {
$errmsg["sug"] = "<p>Please fill in your comments</p>";
}
// Since you have extracted the variables from the
// $_POST array you don't have to set them here,
// just do whatever it is you wanted with the info,
// emailing it or sticking it in a db.
}
if(!count($errmsg) > 0 ) {
header("Location: thankyou.php");
}
Hopefully this will do what you want. Using an array allows you to only have to run one if statement, you can add as many input box names as keys to the array as you want.
Oh yeah, whenever you want to display the error message later on the page just put in this (example uses the name field):
if(isset($errmsg["name"])) { echo $errmsg["name"]; }