• Resolved bugsbunnny

    (@bugsbunnny)


    Hi, everyone!

    I have a problem, I want to create some function after quiz submit. How I can do that?
    For example, I want to get quiz results and if percent of correct answers is more than 80 I want to create a custom certificate for that user.
    Can someone give me some examples of how I can do that? I know that I need to use hooks, exactly qsm_quiz_submitted

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter bugsbunnny

    (@bugsbunnny)

    add_action('qsm_quiz_submitted', 'create_certificate_for_user');
    function create_certificate_for_user()
    {
        // how to get results and then compare score 
    }

    I need to get all results and compare scores so that I can generate a certificate only for users who passed the test successful
    anyone can help me, please?

    Hi @bugsbunnny

    If you want you can check the certificate addon that will resolve your issue.

    Please check below-given documentation link for your reference.

    https://quizandsurveymaster.com/docs/add-ons/certificate/

    Regards,
    Sumit

    Thread Starter bugsbunnny

    (@bugsbunnny)

    I don’t that yet, I did it manually. I just want to know how to use hooks.
    Already I can’t get all result on hook, I just write some info to DB and can’t get scores, for example

    Hi @bugsbunnny

    I need to discuss this with my development team. Hopefully, I will get back to you with the solution.

    Regards,
    Sumit

    Hi @bugsbunnny,

    Please check below-given code for adding custom functionality and code on the result page.

    /*Function after submit quiz
    ** @param array $results_array array like points, ansers etc
    ** @param int $results_id result ID
    ** @param obj $qmn_quiz_options quiz options
    ** @param array $qmn_array_for_variables
    */
    function create_certificate_for_user( $results_array, $results_id, $qmn_quiz_options, $qmn_array_for_variables ){
    //you can add your code here
    }
    add_action(‘qsm_quiz_submitted’, ‘create_certificate_for_user’, 10, 4);

    Regards,
    Sumit

    I had the same question and found very little other than a list of Hooks with no parameters or additional data. After a number of hours of trial and error I did find a solution that worked for me and thought I would share here. In my case I ran the qsm_quiz_submitted hook which looks something like:

    add_action(‘qsm_quiz_submitted’, ‘mmm_get_data’, 10, 4 );
    function mmm_get_data( $results_array, $results_id, $qmn_quiz_options, $qmn_array_for_variables ) {
    …Your code here to capture quiz data and do something with it. Note running an echo here will probably break the quiz plugin…
    }

    I found that the $qmn_array_for_variables array stored all of the quiz results data that I needed. For reference, here is an output of how that array is structured. I will leave it up to you to figure out how to grab the data you need. The second array will need to be looped through to get each question/answer. The ‘correct’ field lists if the answer was ‘correct’ or ‘incorrect’. All of the other fields are pretty self explanatory. Best of luck!

    $qmn_array_for_variables = array (
    'quiz_id' => '1',
    'quiz_name' => 'test',
    'quiz_system' => '0',
    'quiz_payment_id' => '',
    'user_ip' => '###.###.###.###',
    'form_type' => '0',
    'user_name' => 'Test Test',
    'user_business' => 'None',
    'user_email' => '[email protected]',
    'user_phone' => '##########',
    'user_id' => 0,
    'timer' => 10,
    'timer_ms' => 0,
    'time_taken' => '05:14:21 PM 02/05/2023',
    'contact' =>
    array (
    0 =>
    array (
    'label' => 'Name',
    'value' => 'Test Test',
    'use' => 'name',
    'type' => 'text',
    ),
    1 =>
    array (
    'label' => 'Email',
    'value' => '[email protected]',
    'use' => 'email',
    'type' => 'email',
    ),
    2 =>
    array (
    'label' => 'Phone',
    'value' => '##########',
    'use' => 'phone',
    'type' => 'text',
    ),
    ),
    'hidden_questions' => NULL,
    'total_points' => 0,
    'total_score' => ##.##,
    'total_correct' => #,
    'total_questions' => #,
    'question_answers_display' => '',
    'question_answers_array' =>
    array (
    0 =>
    array (
    0 => '',
    1 => 'Submitted Answer',
    2 => 'Correct Answer',
    3 => '',
    'user_answer' =>
    array (
    1 => 'Submitted Answer',
    ),
    'correct_answer' =>
    array (
    0 => 'Correct Answer',
    ),
    'correct' => 'correct',
    'id' => '1',
    'points' => 0,
    'category' => '',
    'multicategories' =>
    array (
    ),
    'question_type' => '0',
    'question_title' => 'Test Question #1',
    'user_compare_text' => '',
    'case_sensitive' => '',
    ),
    ),
    'total_possible_points' => #,
    'total_attempted_questions' => #,
    'minimum_possible_points' => #,
    'comments' => '',
    'response_saved' => 1,
    'result_id' => ##,
    'result_unique_id' => '######',
    )
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to use hooks after submitting’ is closed to new replies.