lundi 2 mars 2015

AJAX email form will not submit

I have a email signup form on my site that I recently added validation to.


Now the for will not send or provide an error message. When I check the inspector I see an error of "TypeError: null is not an object (evaluating 'document.getElementById(update[0]).innerHTML = update[1]')"


This is my contact.php file



<?php
$to = "hello@interzonestudio.com";
$subject_prefix = "";

if(!isset($_GET['action']))

$subject = "Newsletter Sign Up"; //The senders subject
$message = trim($_GET['email']); //The senders subject
$email = trim($_GET['email']); //The senders email address

if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {

mail($to,$subject,$message,"From: ".$email."");

echo 'contactarea|<div id="thanks">Thank you. We promise you won’t regret it.</div>';

else {
echo("$email is not a valid email address");
}
?>


This is my form in HTML



<div id="contactarea">
<span style="font-family: 'Old Standard TT', serif;">Newsletter</span>
<form id="contactform" name="contactform" >
<input class ="email" type="text" name="email" id="inputbox" value="E-Mail"
onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<input type="submit" value="Submit" name="send" onclick="sendemail(); return false; " class="signup" >
</form>
</div>


and this is my javascript



<script language="javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sendemail() {
var email = document.contactform.email.value;
document.contactform.send.disabled=true;
http.open('get', 'contact.php?email='+email+'&action=send');
http.onreadystatechange = handleResponse;
http.send(null);

setTimeout(function(){
jQuery(document).find("#thanks").fadeOut();
},3000);

}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
</script>


Any insight would be greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire