• Resolved Johan Philip

    (@johanvarghese)


    Hey!
    Is it possible that a user can ask for like we ask ‘How many questions do you want’ and there is a text field. They can type 10 and they’ll get 10 questions.

Viewing 1 replies (of 1 total)
  • Plugin Author Harmonic Design

    (@harmonic_design)

    Is it possible? Yes!
    Is it built-in or easy to integrate? No 🙁

    The problem with your request is that you cannot load the quiz or any questions until the user has entered how many questions they want to load.

    I think that the best way to do this is with a URL parameter ($_GET request).

    So, for example, if the URL to your quiz is https://domain.com/quiz, then changing it to https://domain.com/quiz?hdq_questions=10 would tell HD Quiz to load 10 questions from the quiz.

    So how to implement something like this? If you are not a developer or willing to hire one, then you can’t. However, I still want to outline the following steps in case you are.

    The good news is that almost everything you would need to do can be done by using HD Quizz’s built-in actions and hooks.

    First, add a JavaScript function using the hdq_after hook. In this function, you will do two things. The first is you will check for the $_GET value.

    If the value exists, great! If it doesn’t then we know that the user still needs to let us know how many questions they want to see. So if the value does not exist, then we use a JavaScript function to A) hide the quiz, and B) show a form with an number input field for the user to enter how many questions they want.

    Now that we have figured out how to A) allow the user to let us know how many questions they want, and B) created a way to check to see if they’ve entered anything, the hard part is over. What we need to do now is edit HD Quiz to change it to use the $_GET value.

    For that, edit hd-quiz/includes/template.php and on line 71, we need to modify the $per_page variable. Something like this

    
    if(isset($_GET["hdq_questions"])){
        $per_page = intval($_GET["hdq_questions"]);
        $paginate = false;
    }
    

    I hope the above makes sense and at least gets you on the right path, and please let me know if you need further assistance.

Viewing 1 replies (of 1 total)

The topic ‘Text’ is closed to new replies.