...

View Full Version : Contact Form, Please Wait Message Question



theflyingminstr
03-12-2009, 10:50 PM
Hi I am a litle new to PHP and I was wondering if someone could help me out with adding a "please wait.." message/page to this script.

Thanks so much!



<form name="email" method="POST" action="contact.php" />

<input type="text" name="name" /><br />
<input type="text" name="email" /><br />
<input type="text" name="phone" /><br /><br />
<textarea rows="3" name="message" /></textarea>
<br /><br />
<input type="submit" value="Send" name="submit">

</form>



contact.php

<?php


// get posted data into local variables
$EmailFrom = "webmaster@domain.com";
$EmailTo = "email@domain.com, email2@domain.com";
$Subject = "Inquiry from Website.com";
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$phone = Trim(stripslashes($_POST['phone']));
$message = Trim(stripslashes($_POST['message']));


// Select if you want to check form for standard spam text
$SpamCheck = "Y"; // Y or N
$SpamReplaceText = "*content removed*";
// Error message prited if spam form attack found
$SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.
</font><br><b>Your IP Number of <b>".getenv("REMOTE_ADDR")."</b> has been logged.</b></p>";

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}


if ($SpamCheck == "Y") {
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();}

// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string

$name = preg_replace($pattern, "", $name);
$email = preg_replace($pattern, "", $email);
$message = preg_replace($pattern, "", $message);

// Check for the injected headers from the spammer attempt
// This will replace the injection attempt text with the string you have set in the above config section
$find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i");
$email = preg_replace($find, "$SpamReplaceText", $email);
$name = preg_replace($find, "$SpamReplaceText", $name);
$message = preg_replace($find, "$SpamReplaceText", $message);

// Check to see if the fields contain any content we want to ban
if(stristr($name, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
if(stristr($message, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}

// Do a check on the send email and subject text
if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
if(stristr($subject, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
}

$headers = "From: Website.com <email@domain.com>\r\n";
$headers .= "Reply-To: ".$name." <".$email.">\r\n";
$headers .= "Return-Path: ".$name." <".$email.">\r\n";

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Inquiry: ";
$Body .= $message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, $headers);

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=post-contact.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=post-contact-not-sent.htm\">";
}
?>

Fumigator
03-12-2009, 11:01 PM
At what point in your webpage process do you want "please wait" to display and what would we be waiting for?

theflyingminstr
03-12-2009, 11:04 PM
I'm thinking right when they click submit? The actual form I'm using has quadruple the amount of inputs than this example that's why I want a please wait message.

Thank you

Fumigator
03-12-2009, 11:12 PM
You can use Javascript for that... no need to bother PHP with it. Look into the onsubmit() event:

http://www.w3schools.com/js/js_events.asp

You then set up an invisible DIV with the please wait message in it, and use document.getElementById("msgdiv").style.visibility="visible"; in your Javascript function to make it visible.

http://www.w3schools.com/htmldom/prop_style_visibility.asp

theflyingminstr
03-12-2009, 11:16 PM
Awesome, thanks so much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum