Tobe_Sta
05-21-2011, 06:32 AM
Hey,
I have a compatibility issue with my contact form with Internet Explorer 7 and below. When I fill out the form correctly and click submit, nothing happens. I have posted the html, js and php, though I took the js out and that didn't help, so at a guess I'd say it's an issue with the php. All newer browsers function perfectly using this code.
Here is my html of the form
<form name="contactform" action="contactengine.php" method="post" class="formcontainer" onSubmit="javascript:validate(); return false;">
<label>Name:</label>
<input type="text" name="name"/>
<label>Email:</label>
<input type="text" name="email"/>
<label>Subject:</label>
<input type="text" name="subject" id="subject"/>
<label>Message:</label>
<textarea name="message"></textarea>
<button> Submit! </button>
</form>
The javascript:
function validate()
{
if (document.contactform.name.value =="")
{
alert("Name can't be left blank!");
return false;
}
if (document.contactform.email.value =="" || (document.contactform.email.value.search("@") == -1 ||( document.contactform.email.value.search("com") == -1 && document.contactform.email.value.search("net") == -1 && document.contactform.email.value.search("au") == -1 && document.contactform.email.value.search("org") == -1)))
{
alert("Please enter a valid email address!");
return false;
}
if (document.contactform.subject.value =="")
{
alert("Subject can't be left blank!");
return false;
}
if (document.contactform.message.value =="")
{
alert("Please enter a comment or question!");
return false;
}
document.contactform.submit();
}
And finally, the PHP:
<?php
$EmailFrom = "contact@website.com";
$EmailTo = "tobe_sta@hotmail.com";
$Subject = $_REQUEST['subject'];
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
if(isset($_POST["title"]) && strlen($_POST["title"])){
die("SPAM BOT");
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Thanks in advance for any comments/help.
Toby.
I have a compatibility issue with my contact form with Internet Explorer 7 and below. When I fill out the form correctly and click submit, nothing happens. I have posted the html, js and php, though I took the js out and that didn't help, so at a guess I'd say it's an issue with the php. All newer browsers function perfectly using this code.
Here is my html of the form
<form name="contactform" action="contactengine.php" method="post" class="formcontainer" onSubmit="javascript:validate(); return false;">
<label>Name:</label>
<input type="text" name="name"/>
<label>Email:</label>
<input type="text" name="email"/>
<label>Subject:</label>
<input type="text" name="subject" id="subject"/>
<label>Message:</label>
<textarea name="message"></textarea>
<button> Submit! </button>
</form>
The javascript:
function validate()
{
if (document.contactform.name.value =="")
{
alert("Name can't be left blank!");
return false;
}
if (document.contactform.email.value =="" || (document.contactform.email.value.search("@") == -1 ||( document.contactform.email.value.search("com") == -1 && document.contactform.email.value.search("net") == -1 && document.contactform.email.value.search("au") == -1 && document.contactform.email.value.search("org") == -1)))
{
alert("Please enter a valid email address!");
return false;
}
if (document.contactform.subject.value =="")
{
alert("Subject can't be left blank!");
return false;
}
if (document.contactform.message.value =="")
{
alert("Please enter a comment or question!");
return false;
}
document.contactform.submit();
}
And finally, the PHP:
<?php
$EmailFrom = "contact@website.com";
$EmailTo = "tobe_sta@hotmail.com";
$Subject = $_REQUEST['subject'];
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
if(isset($_POST["title"]) && strlen($_POST["title"])){
die("SPAM BOT");
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Thanks in advance for any comments/help.
Toby.