mcallaro88 Posted October 25, 2009 Share Posted October 25, 2009 I have a php page and I'm using jQuery and some AJAX to validate my contact form (phpmailer & process.php). However, the message is never displayed in my email. The name, email, and subject get passed but the message always comes back as Message: [object HTMLTextAreaElement]. Could someone tell me what I'm doing wrong I've tried everything but nothing is working. Thanks for all who help - MIKE Here is the form HTML ------------------------------------------------------------------------------------------------------------------- <div id="forminfo"> <form name="contact" method="post" action=""> <dl> <dt id="name"><label for="fName" class="">Name</label></dt> <dd><input type="text" class="text" name="fName" id="fName" style="width:200px; height:20px;" /></dd> <label class="error" for="fName" id="fName_error">This field is required.</label> <dt id="eMail"><label for="email" class="">Email</label></dt> <dd><input type="text" class="text" name="email" id="email" style="width:200px; height:20px;" /></dd> <label class="error" for="email" id="email_error">This field is required.</label> <dt id="subject"><label for="subject">Subject</label></dt> <dd><input type="text" size="8" maxlength="40" name="subject" id="subj" style="width:200px; height:20px;" class="text" /></dd> <label class="error" for="subject" id="subj_error">This field is required.</label> <dt id="comments">Message</dt> <dd><textarea name="memo" class="text2" id="memo"></textarea></dd> <dd><input type="submit" class="button" id="submit" name="submit" value="" /></dd> </dl> </form> </div><!--forminfo--> Here is the php ------------------------------------------------------------------------------------------------------------------- <?php if ((isset($_POST['fName'])) && (strlen(trim($_POST['fName'])) > 0)) { $name = stripslashes(strip_tags($_POST['fName'])); } else {$name = 'No name entered';} if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) { $email = stripslashes(strip_tags($_POST['email'])); } else {$email = 'No email entered';} if ((isset($_POST['subj'])) && (strlen(trim($_POST['subj'])) > 0)) { $subject = stripslashes(strip_tags($_POST['subj'])); } else {$subject = 'No subject entered';} if ((isset($_POST['memo'])) && (strlen(trim($_POST['memo'])) > 0)) { $comments = stripslashes(strip_tags($_POST['memo'])); } else {$comments = 'No message entered';} ob_start(); ?> <html> <head> <style type="text/css"> </style> </head> <body> <table width="550" border="1" cellspacing="2" cellpadding="2"> <tr bgcolor="#eeffee"> <td>Name</td> <td><?=$name;?></td> </tr> <tr bgcolor="#eeeeff"> <td>Email</td> <td><?=$email;?></td> </tr> <tr bgcolor="#eeffee"> <td>Subject</td> <td><?=$subject;?></td> </tr> <tr bgcolor="#eeffee"> <td>Message</td> <td><?=$comments;?></td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Alex Posted October 25, 2009 Share Posted October 25, 2009 You didn't really post the part of the code that's relevant to your problem. We'd need to see the AJAX portion of this. But because of the error I can tell you that your problem is almost certainly that you're passing the actual object into the HTTP request rather than the value of that element. So the solution would be to add ".value" to what you're passing to access the value attribute of the object. For a more specific solution you'll need to post the relevant code. Quote Link to comment Share on other sites More sharing options...
mcallaro88 Posted October 25, 2009 Author Share Posted October 25, 2009 Sorry about that I knew I forgot to put something lol here is the AJAX stuff $(function() { $('.error').hide(); $('input.text-input').css({backgroundColor:"#FFFFFF"}); $('input.text-input').focus(function(){ $(this).css({backgroundColor:"#FFFFFF"}); }); $(".button").click(function() { // validate and process form // first hide any error messages $('.error').hide(); var name = $("input#fName").val(); if (name == "") { $("label#fName_error").show(); $("input#fName").focus(); return false; } var email = $("input#email").val(); if (email == "") { $("label#email_error").show(); $("input#email").focus(); return false; } var subject = $("input#subj").val(); if (subject == "") { $("label#subj_error").show(); $("input#subj").focus(); return false; } var message = $("input#memo").val(); if (message == "") { $("input#memo").focus(); return false; } var dataString = 'fName='+ name + '&email=' + email + '&subj=' + subject + '&memo=' + memo; //alert (dataString);return false; $.ajax({ type: "POST", url: "bin/process.php", data: dataString, success: function() { $('.formContainer').html("<div id='message'></div>"); $('#message').html("<h2>Contact Form Submitted!</h2>") .append("<p>I will be in touch soon.</p>") .hide() .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='images/check.png' />"); }); } }); return false; }); }); runOnLoad(function(){ $("input#fName").select().focus(); }); Quote Link to comment Share on other sites More sharing options...
Alex Posted October 25, 2009 Share Posted October 25, 2009 Just as I suspected, look at this line: var dataString = 'fName='+ name + '&email=' + email + '&subj=' + subject + '&memo=' + memo; You're using memo, which is actually an object. You should be using the variable that you defined for the value of that object. Which is message, so it should be this: var dataString = 'fName='+ name + '&email=' + email + '&subj=' + subject + '&memo=' + message; Also, in the future you should use [ code ] or [ php ] (without the spaces) tags. Quote Link to comment Share on other sites More sharing options...
mcallaro88 Posted October 25, 2009 Author Share Posted October 25, 2009 Ok I did what you said and now I'm getting a an undefined. I have no idea what that means. Why am I getting this error? Quote Link to comment Share on other sites More sharing options...
trq Posted October 25, 2009 Share Posted October 25, 2009 You aware this is the PHP Help board? Quote Link to comment Share on other sites More sharing options...
mcallaro88 Posted October 25, 2009 Author Share Posted October 25, 2009 Yes I'm aware an I'm asking a question about php with some AJAX thats all. I've been trying to figure this out all day and nothing so I need some help. Is there a problem with what I'm asking? Quote Link to comment Share on other sites More sharing options...
Alex Posted October 25, 2009 Share Posted October 25, 2009 According to your code posted previously it should work. All I modified was memo to message, and in that code message is defined. Post the new JS source, in code tags. Quote Link to comment Share on other sites More sharing options...
trq Posted October 25, 2009 Share Posted October 25, 2009 Is there a problem with what I'm asking? We have an ajax board. Ask your question there. Quote Link to comment Share on other sites More sharing options...
mcallaro88 Posted October 25, 2009 Author Share Posted October 25, 2009 @thorpe - alright I wasn't aware you had an ajax board just thought it was php. I didn't really have a chance to browse the site yet but thanks. @AlexWD - I changed it to message and that's what I got was an undefined message. Quote Link to comment Share on other sites More sharing options...
mcallaro88 Posted October 25, 2009 Author Share Posted October 25, 2009 $(function() { $('.error').hide(); $('input.text-input').css({backgroundColor:"#FFFFFF"}); $('input.text-input').focus(function(){ $(this).css({backgroundColor:"#FFFFFF"}); }); $(".button").click(function() { // validate and process form // first hide any error messages $('.error').hide(); var name = $("input#fName").val(); if (name == "") { $("label#fName_error").show(); $("input#fName").focus(); return false; } var email = $("input#email").val(); if (email == "") { $("label#email_error").show(); $("input#email").focus(); return false; } var subject = $("input#subj").val(); if (subject == "") { $("label#subj_error").show(); $("input#subj").focus(); return false; } var message = $("input#memo").val(); if (message == "") { $("input#memo").focus(); return false; } var dataString = 'fName='+ name + '&email=' + email + '&subj=' + subject + '&memo=' + message; //alert (dataString);return false; $.ajax({ type: "POST", url: "bin/process.php", data: dataString, success: function() { $('.formContainer').html("<div id='message'></div>"); $('#message').html("<h2>Contact Form Submitted!</h2>") .append("<p>I will be in touch soon.</p>") .hide() .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='images/check.png' />"); }); } }); return false; }); }); runOnLoad(function(){ $("input#fName").select().focus(); }); Quote Link to comment Share on other sites More sharing options...
Alex Posted October 25, 2009 Share Posted October 25, 2009 Well it's clearly defined.. what if you try $("input#memo").val();? Quote Link to comment Share on other sites More sharing options...
mcallaro88 Posted October 25, 2009 Author Share Posted October 25, 2009 Nope I don't know why it is saying undefined lol. I bet its something really small but I don't know what it could be. I have been trying to get this for like hours and I'm getting frustrated. Gotta love code. Quote Link to comment Share on other sites More sharing options...
OfcaPL Posted January 9, 2013 Share Posted January 9, 2013 sorry that I'm refreshing such an old topic - but I've got similiar issue (and I see we were using same tutorial for doing it) and for anyone who will have in the future similiar problem: check the line with var message = $("input#memo").val(); and in his form that field wasn't just an INPUT but a TEXTAREA - and that was the problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.