March 17, 201214 yr Hello all, I have been following a tutorial to get a contact form to send and display a message without refreshing the page here - http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/ Got it to work fine and integrated it with my website. The problom occurs when I add a textarea, it will validate it fine but will not send the contents in the email. If anyone would be able to shed some light on why this may be that would be amazing. html, js and php code here - they are simple just for testing. <form name="contact" method="post" action=""> <fieldset> <label for="name" id="name_label">Name</label> <label class="error" for="name" id="name_error">This field is required.</label> <input type="text" name="name" id="name" size="30" value="" class="text-input" /> <label for="email" id="email_label">Return Email</label> <label class="error" for="email" id="email_error">This field is required.</label> <input type="text" name="email" id="email" size="30" value="" class="text-input" /> <label for="phone" id="phone_label">Return Phone</label> <label class="error" for="phone" id="phone_error">This field is required.</label> <input type="text" name="phone" id="phone" size="30" value="" class="text-input" /> </fieldset> <fieldset> <label for="test">Message</label> <label class="error" for="test" id="test">This field is required.</label> <textarea type="test" id="test" name="test" size="30" value="" class="text-input""></textarea> <input type="submit" name="submit" class="button" id="submit_btn" value="Send" /> </fieldset> </form> $(function() { $('.error').hide(); $('input.text-input').css({backgroundColor:"#FFFFFF"}); $('input.text-input').focus(function(){ $(this).css({backgroundColor:"#FFDDAA"}); }); $('input.text-input').blur(function(){ $(this).css({backgroundColor:"#FFFFFF"}); }); $(".button").click(function() { // validate and process form // first hide any error messages $('.error').hide(); var name = $("input#name").val(); if (name == "") { $("label#name_error").show(); $("input#name").focus(); return false; } var email = $("input#email").val(); if (email == "") { $("label#email_error").show(); $("input#email").focus(); return false; } var phone = $("input#phone").val(); if (phone == "") { $("label#phone_error").show(); $("input#phone").focus(); return false; } var test = $("textarea#test").val(); if (test == "") { $("label#message_error").show(); $("textarea#test").focus(); return false; } var dataString = 'name='+ name + '&email=' + test + '&test=' + message + '&phone=' + phone; //alert (dataString);return false; $.ajax({ type: "POST", url: "bin/process.php", data: dataString, success: function() { $('#contact_form').html("<div id='message'></div>"); $('#message').html("<h2>Contact Form Submitted!</h2>") .append("<p>We will be in touch soon.</p>") .hide() .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='images/check.png' />"); }); } }); return false; }); }); runOnLoad(function(){ $("input#name").select().focus(); }); <?php $myemail = 'xxxxxx@gmail.com';//<-----Put Your email address here. $name = $_POST['name']; $number = $_POST['phone']; $email = $_POST['email']; $test = $_POST['test']; $to = $myemail; $email_subject = "Quote: $name"; $email_body = "You have received a new message. ". " Here are the details:\n \n Name: $name \n \n Number: $number \n \n Email: $email \n \n test: \n $test"; $headers = "From: $myemail\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); ?> Many thanks!!
March 17, 201214 yr in the javascript find var dataString = 'name='+ name + '&email=' + test + '&test=' + message + '&phone=' + phone; replace with var dataString = 'name='+ name + '&email=' + email + '&test=' + test + '&message=' + message + '&phone=' + phone;
March 17, 201214 yr Author in the javascript find var dataString = 'name='+ name + '&email=' + test + '&test=' + message + '&phone=' + phone; replace with var dataString = 'name='+ name + '&email=' + email + '&test=' + test + '&message=' + message + '&phone=' + phone; Thank you, but still no luck
March 17, 201214 yr ok, well theres more than one bug here then. just noticed an extra quote in the text area html, on the class attribute <textarea type="test" id="test" name="test" size="30" value="" class="text-input""></textarea> fixed version: <textarea type="test" id="test" name="test" size="30" value="" class="text-input"></textarea> Edited March 17, 201214 yr by SniderDK
March 17, 201214 yr <?php $myemail = 'xxxxxx@gmail.com';//<-----Put Your email address here. $name = $_POST['name']; $number = $_POST['phone']; $email = $_POST['email']; $test = $_POST['test']; $to = $myemail; $email_subject = "Quote: ".$name; $email_body = "You have received a new message. \n \n Here are the details:\n \n Name: ".$name." \n \n Number: ".$number." \n \n Email: ".$email." \n \n test: \n ".$test; $headers = "From: ".$myemail; $headers .= "Reply-To: ".$email_address; mail($to,$email_subject,$email_body,$headers); ?> How's this? Edited March 17, 201214 yr by Samus
March 17, 201214 yr thats missing the newline chars in the headers, also changing the way php contructs the string wouldnt fix this issue as there is no diffrence in the end result only how php goes about making the string. the OP said the new textarea he added wasnt put into the email sugesting the email sends but the textarea is not in there... which is the asumption i've been going by... meaning the error would be regarding the test varibale actually getting used.
Create an account or sign in to comment