SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get result of quiz by email ( POST function)

    Hi everybody,

    I'm having lot of trouble since the last days to complete this online quiz I'm doing,
    I've create an online quiz, and I need at the end of it, once submitting ot, to send the name,email and results of this by email.

    I've been trying lot of different ways to do it, but I can not achieve it, If anybody can help me, at least to which way to go ( Im beginning in PHP and Jquery), I'll be really so thanksfull !!!

    here is my Jquery part:

    HTML Code:
    <script>
    $(function(){
        var jQuiz = {
            answers: { q1: 'a', q2: 'a', q3: 'a', q4: 'a', q5: 'a' },
            questionLenght: 5,
            checkAnswers: function() {
                var arr = this.answers;
                var ans = this.userAnswers;
                var resultArr = []
                for (var p in ans) {
                    var x = parseInt(p) + 1;
                    var key = 'q' + x;
                    var flag = false;
                    if (ans[p] == 'q' + x + '-' + arr Smiley key ) {
                        flag = true;
                    }
                    else {
                        flag = false;
                    }
                    resultArr.push(flag);
                }
                return resultArr;
            },
            init: function(){
                $('.btnNext').click(function(){
                    if ($('input[type=radio]:checked:visible').length == 0) {
                                
                        return false;
                    }
                    $(this).parents('.questionContainer').fadeOut(500, function(){
                        $(this).next().fadeIn(500);
                    });
                    var el = $('#progress');
                    el.width(el.width() + 120 + 'px');
                });
                $('.btnPrev').click(function(){
                    $(this).parents('.questionContainer').fadeOut(500, function(){
                        $(this).prev().fadeIn(500)
                    });
                    var el = $('#progress');
                    el.width(el.width() - 120 + 'px');
                })
                $('.btnShowResult').click(function(){
                    var arr = $('input[type=radio]:checked');
                    var ans = jQuiz.userAnswers = [];
                    for (var i = 0, ii = arr.length; i < ii; i++) {
                        ans.push(arr.getAttribute('id'))
                    }
                })   
                 $('.btnShowResult').click(function(){
                    $('#progress').width(300);
                    $('#progressKeeper').hide();
                    var results = jQuiz.checkAnswers();
                    var resultSet = '';
                    var trueCount = 0;
                    for (var i = 0, ii = results.length; i < ii; i++){
    					 
                    }
                    resultSet += '<div class="totalScore"></br>Your total score is ' + trueCount * 1 + ' / 5</div>'
                    $('#resultKeeper').html(resultSet).show(); 
    				
    				if (trueCount > 4) {
     resultSet += '<div class="totalScoreok"></br>CONGRATULATION YOU PASS, why not to try the next level ?</div>'
                    $('#resultKeeper').html(resultSet).show();
    				                    }
    									
    									  if (trueCount <= 4 && trueCount >2)  {
     resultSet += '<div class="totalScoreok"></br>YOUR LEVEL IS OK</div>'
                    $('#resultKeeper').html(resultSet).show();            
    				        }	
    				
    				 if (trueCount <= 2) {
     resultSet += '<div class="totalScoreok"></br>YOU SUCK</div>'
                    $('#resultKeeper').html(resultSet).show();
    				                    }
    				
                })
            }
        };
    	
    
        jQuiz.init();
    })
    my PHP submit:

    PHP Code:
    <?php $name $_POST['name'];
    $email $_POST['email'];
    $message $_POST['message'];
    $formcontent="From: $name \n Message: $message";
    $formcontent .= $totalScoreok " out of 5 correct!\n ";
    $recipient "thibault.rolando@gmail.com";
    $subject "Contact Form Kino Web";
    $mailheader "From: $email \r\n";
    mail($recipient$subject$formcontent$mailheader) or die("Error!");
    echo 
    "Your email has been send, thank you";
    sleep(1);//seconds to wait..
    header("Location:http://www.kinosurface.com/sucess.html");
    ?>
    the information I want to add are basicly the class 'totalScoreok' and the id "resultKeeper"

    I've been trying to play aroundn and also add this function in the jquery part, but I dont receive anything with it.

    HTML Code:
    $(function() {
          $('#button').click(function(e) {
                e.preventDefault();
                $.ajax({
                      url:'<submit.php>',
                      type:'POST',
                      data:{'message':$('.totalScoreok').html(),'subject':'Subject of your e-mail'},
                      success:function(data) {
                            alert('You data has been successfully e-mailed');
                            alert('Your server-side script said: ' + data);
                      }
                });
          });
    });
    here is the part of my html part with the submit button, if it can help . ..

    HTML Code:
        <div class="btnContainer">
            <div class="prev">
                <a class="btnPrev">&lt;&lt; Prev</a>
            </div>
            <div class="next">
    
    <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">
    
        </form>
    
     </div>
    I really appreciate any highlites,

    thanks in advances =)

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2013
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are redirecting to a new page in PHP after the form is submitted, why are you using jquery?? Seems a bit counter intuitive


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •