Hello to all php gurus,
I'm new here and hoping someone kind can help me with a small issue on php form i have.
1st i would like is to echo a success message the same way the script echos error messages when one of the form feilds is empty.
2nd is i would like to do this by adding a peice of code where i want the success message to appear.
For the error messages the script uses this piece of code here to echo the error messages where i want it to appear. "<? echo $error; ?>"
if possible i want to use a similar code to echo the success message where i want it to appear, the full form code is below.
<?
// Attention! Please read the following.
// It is important you do not edit pieces of code that aren't tagged as a configurable options identified by the following:
// Configuration option.
// Each option that is easily editable has a modified example given.
$error = '';
$name = '';
$email = '';
//$phone = ''; Remove the // tags and this text to active phone number.
$subject = '';
$comments = '';
$verify = '';
if(isset($_POST['contactus'])) {
$name = $_POST['name'];
$email = $_POST['email'];
//$phone = $_POST['phone']; Remove the // tags and this text to active phone number.
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
// Configuration option.
// You may change the error messages below.
// e.g. $error = 'Attention! This is a customised error message!';
if(trim($name) == '') {
$error = '<div class="error_message">Attention! You must enter your name.</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Attention! Please enter a valid email address.</div>';
// Configuration option.
// Remove the // tags below to active phone number.
//} else if(!is_numeric($phone)) {
// $error = '<div class="error_message">Attention! Phone number can only contain digits.</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
}
if(trim($subject) == '') {
$error = '<div class="error_message">Attention! Please enter a subject.</div>';
} else if(trim($comments) == '') {
$error = '<div class="error_message">Please enter your message.</div>';
} else if(trim($verify) == '') {
$error = '<div class="error_message">Attention! Please enter the verification number.</div>';
} else if(trim($verify) != '4') {
$error = '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "
[email protected]";
$address = "
[email protected]";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards to $subject, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
// Configuration option.
// RIf you active phone number, swap the tags of $e-reply below to include phone number.
//$e_reply = "You can contact $name via email, $email or via phone $phone";
$e_reply = "You can contact $name via email, $email";
$msg = $e_body . $e_content . $e_reply;
mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
// Email has sent successfully, echo a success page.
echo "<div id='succsess_page'>";
echo "<em>Email Sent Successfully.</em>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
}
}
if(!isset($_POST['contactus']) || $error != '') // Do not edit.
{
?>
Thanks in advance