Data submit with ajax get result but not contact form

Hi everybody !

I’m struggling since few days with that,

I have a online quiz by jQuery, I want once the user submit it, to send the results with the contact information’s of the users to the moderator.

I make it work, sending the results information correctly, the problem is it doesn’t send the user information.
I’ve been playing around with different solution’s, I can manage or to have the user information or the results of the quiz, but not both at the same time !

If anybody can highlight me, I will really be so thankful !!
!
Here is the “contact form”:

[code]

<label>Name</label>
<input name="name" placeholder="Type Here">
        
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
        
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
        
<input id="button" type="submit" value="Send" class="btnShowResult">
</div>
Status Bar
[/code]

Here is the jQuery part about the ajax to send the data result of the quiz, the div #resultKeeper being the result I want to receive

[code]
$(function() {
$(’#form’).on(‘submit’,function(e) { e.preventDefault();
$.ajax({
url:‘submit.php’,
type:‘POST’,
data:{‘results’:$(’#resultKeeper’).html(),‘subject’:‘Subject of your e-mail’},
success:function() {
$(’#responseMessage’).html()
}
});
return false;

});
}); [/code]

here is my PHP

[php]

<?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $results = $_POST['results']; $formcontent="From: $name \n Message: $message \n Results: \n $results"; $recipient = "[email protected]"; $subject = "my subject"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Your email has been send, thank you"; ?>[/php]

If in the Jquery I change the #form

$(function() { $('#form').on('submit',function(e)

by #button instead of #form, I receive the informations from the contact form, but not anymore from the results.

Also by keeping the #form, I receive the result of the quiz, and few value as the form content, but not the informations from the placeholder !, here is what I receive by email:

" From: Message: Results: Question 1 is true Question 2 is false Question 3 is true Question 4 is false Question 5 is false
Your total score is 2 / 5
CONGRATULATION, YOUR LEVEL IS A1.1"

As we can see I have the From: and Message: appearing, but not the proper name and message that the user are writting … .

Anyhelp will be adorable !!

Here is the allcode of JSFiddle:

http://jsfiddle.net/ccwJJ/

Thank you in advance !!

I’m by no means a jQuery Expert, but I’m just going to point out things I don’t understand the logic to, perhaps it will make a little sense to you and you’ll be able to figure it out.

I’m assuming the

[php]$email = $_POST[‘email’];[/php]

is blank as well…

In your jquery

[php] $(function() {
$(’#form’).on(‘submit’,function(e) { e.preventDefault();
$.ajax({
url:‘submit.php’,
type:‘POST’,
data:{‘results’:$(’#resultKeeper’).html(),‘subject’:‘Subject of your e-mail’},
success:function() {
$(’#responseMessage’).html()
}
});
return false;

});
}); [/php]

It seams you’re only passing the resultkeeper data in into the post…

Maybe if you did something like this…

[php] $(function() {
$(’#form’).on(‘submit’,function(e) { e.preventDefault();
$.ajax({
url:‘submit.php’,
type:‘POST’,
data:{‘results’:$(’#resultKeeper’).html(),‘subject’:‘Subject of your e-mail’,‘message’:$(#message’).html()},
success:function() {
$(’#responseMessage’).html()
}
});
return false;

});
}); [/php]

That will pass in your message information into the post.

Sponsor our Newsletter | Privacy Policy | Terms of Service