Just seen your post as i was writting this so il post anyway, what i can see seems alot easyier, have alook at my code and see what you think.
Just trying to understand all this - thanks guys. So what your saying is have all the code on the same page? I currently have my code in a diffrent file like below
HTML Code:
<form name="contact" method="post" action="process.php" target="_self">
process.php:
PHP Code:
?
//validate the name and combat magic quotes, if necessary
$do_name = true;
if (!empty($_REQUEST['name'])) {
$name = stripslashes($_POST['name']);
} else {
$do_name = false;
echo '<p>You forgot to enter your name!</p>';
}
//validate the email and check if necessary chars are present and email is not blank
$do_email = true;
if(eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $_POST['email'])) {
$email = $_POST['email'];
} else {
$do_email = false; // NOTE THIS LINE
echo "<p>Not a valid email address</p>\n";
}
//validate the category and combat magic quotes, if necessary
$do_category = true;
if (!empty($_REQUEST['category'])) {
$category = $_POST['category'];
} else {
$do_category = false;
echo '<p>Please select a category!</p>';
}
//validate the comment and combat magic quotes, if necessary
$do_comment = true;
if (!empty($_REQUEST['comment'])) {
$comments = stripslashes($_POST['comment']);
} else {
$do_comment = false;
echo '<p>You forgot your comments!</p>';
}
// arrange category options
$to="email@site.com";
$message = "$name just filled in your contact form. They said:\n$comments\n\nTheir e-mail address was: $email";
switch($category) {
case 'enquires' :
$subject = 'Enquires';
break;
case 'clubs' :
$subject = 'Clubs';
break;
case 'pictures' :
$subject = 'Pictures';
break;
case 'advertise' :
$subject = 'Advertise';
break;
}
// check and send to my email account
if ($do_name && $do_email && $do_category && $do_comment) {
if(mail($to,$subject,$message,"From: $email\n")) {
// succesful? redirect
header("Location: index1.php");
exit();
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
}
?>
sorry if its abit full on just trying to learn stuff still at the novice stage.
thanks in advance
Bookmarks