Jump to content

Data submit with ajax get result but not contact form


tibewww

Recommended Posts

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":

<div class="questionContainer radius hide">
<form action="submit.php" method="POST" id="form">
        
    <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">
        
</form>  
        
    </div>
       
    
   
<div class="txtStatusBar">Status Bar</div>
<div id="progressKeeper" class="radius">
    <div id="progress"></div>
</div>
<div id="resultKeeper" class="radius hide"></div>
</div>

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

$(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;

});
}); 

here is my 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 = "thibault.rolando@gmail.com";
$subject = "my subject";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Your email has been send, thank you";
?>

If in the Jquery I change the

$(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 keepin 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 !!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.