• Resolved cicini

    (@cicini)


    When the Question Type uses Text Based Answer, the answer can be obtained directly by viewing the HTML (even if the function of displaying the answer after answering the question is turned off)
    I have not tested other Question Types for the same problem



    • This topic was modified 2 years, 7 months ago by cicini.
    • This topic was modified 2 years, 7 months ago by cicini.
    • This topic was modified 2 years, 7 months ago by cicini.
Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Harmonic Design

    (@harmonic_design)

    Hi cicini,
    this is technically true for all question types. HD Quiz does not contact the server for each and every question (or indeed any questions). As a free WordPress plugin, I have zero control over the sites and servers that host HD Quiz, so everything is done client-side in order to maximize compatibility, speed, feature set, and customizability.

    As you can tell, the data is obfuscated so that the average user who pokes around the source code will not see the solutions in plaintext, but the data IS there.

    HD Quiz is meant to put fun interactive quizzes on your website – it is not a full-fledged LMS (Learning Management System) plugin. So if this is a dealbreaker for you then I’m afraid you will have to find a different quiz solution for your site, or you can modify HD Quiz yourself to only mark serverside (let me know if you would like direction on how to do this).

    Thread Starter cicini

    (@cicini)

    If possible, please teach me how to modify it, thanks.

    Plugin Author Harmonic Design

    (@harmonic_design)

    Sure, i’ll send you a writeup tomorrow. The general steps will be

    1. Change HD Quiz version # to stop future updates
    2. Edit question templates
    3. Replace default “quiz completion” function with our custom one
    Thread Starter cicini

    (@cicini)

    thank you.

    Plugin Author Harmonic Design

    (@harmonic_design)

    OK, so these edits will do what you need to do, but there are two things to be aware of.

    1) This will not work for the “select all that apply” question type. This solution would need to be extended to allow for that.

    2) This will not mark (visually highlight) which questions and answers were right or wrong – although I added in the skeleton on how to get that data so that you can add this in if you want.

    STEPS.
    First, let’s change the plugin version so that my future releases don’t overwrite your changes.

    Edit the plugin’s index.php and change the version number to something like 99.9.9. Change on both lines 8 and 19.

    – – – – –

    Now we need to edit the question templates to stop the data from printing on the page. Luckily this is very easy for all question types.

    under ./incliudes/templates you will see each of the template files. Edit each of them. the default.php (default multiple choice), change line 14 to se $selected to 0. Do the same for image.php. For text.php, change line 28 to set $correct to an empty string "".

    That’s it!

    – – – – –

    Now we need to edit the main script file. ./includes/js/hdq_script.js. We are looking for the submit function (starts line 628). Replace the entire function with the following: https://pastebin.com/raw/7CFQbPeY

    This stops HD Quiz from doing the normal submit stuff and instead creates a data array of the question id and the selected answer and sends it to the backend for validation. It then receives a new array from the backend, which we use to calculate the score and then continue to do the other HD Quiz stuff like show the results.

    – – – –

    Finally, we add a new function to the backend that validates the submitted questions and answers. Add the following function to the index.php file of the plugin at the very end of the file. https://pastebin.com/raw/UyVuKn7q

    – – – –

    and that’s it!

    Thread Starter cicini

    (@cicini)

    Sorry to bother you again, it seems to only work on English, text submissions in other languages seem to be changed to a number 1, and individual Arabic numbers will plus 1(eg: enter 6 but submit 7)

    Plugin Author Harmonic Design

    (@harmonic_design)

    Hi cicini,
    did you implement any of the suggestions above?

    I think that it’s adding 1 is the clue we need here. In WordPress, calls to admin_ajax return true (which PHP uses a 1 to denote) upon completion.

    So what I think might be happening is that your server-side function is returning “true” instead of echoing out the actual value you want to return.

    The function I gave you returns a JSON encoded string – but languages like Arabic are not valid JSON format.

    Assuming I am correct about my hunches above, you can try changing the json_encode function to add a second parameter to try and force safe unicode.

    Change echo json_encode($data);
    to echo json_encode($data, JSON_UNESCAPED_UNICODE);

    Thread Starter cicini

    (@cicini)

    I confirm that the above suggestions have been implemented.
    Changing the json_encode function still does not make it work on other languages (type: text based on answer). For example, when I use Chinese text as an answer, even if the answer is correct, the score is still 0.
    Modified version:
    hdquiz.7z

    • This reply was modified 2 years, 4 months ago by cicini.
    • This reply was modified 2 years, 4 months ago by cicini.
    • This reply was modified 2 years, 4 months ago by cicini.
    Plugin Author Harmonic Design

    (@harmonic_design)

    Can you provide me with an example of your answers? (choices, and user-submitted answers)

    Thread Starter cicini

    (@cicini)

    Question Type: Text Based Answers

    Example 1:
    Answers:
    子犬
    User-Submited Answers:
    子犬
    Example 2:
    Answers:
    ひなゆあ
    User-Submited Answers:
    ひなゆあ

    In fact, any Chinese and Japanese words have the same problem (I haven’t tested other languages).

    Plugin Author Harmonic Design

    (@harmonic_design)

    Excellent thanks.

    Pretty sure I found the issue. The problem is that I need to think of a good workaround. Stay tuned!

    Thread Starter cicini

    (@cicini)

    Thank you for your hard work and look forward to your success.

    Plugin Author Harmonic Design

    (@harmonic_design)

    I tracked down the issue, and as usual – it was something stupid.

    HD Quiz uses a 0 or 1 for multiple choice questions, and a string for the text as answers. Since we are now sending user-submitted data to the backend, it is ESSENTIAL that we sanitize and clean that data for security.

    The problem is that we have mixed content – we need to sanitize the text-based answers as a string, and the multiple choice answers as an integer.

    For the PHP function hdq_validate_answers you will see the following line: if(preg_match("/[a-z]/i", $a)){

    That if statement is where I was checking to see if the data was a string or a number using regular expression. In English, this is not a problem and works perfectly, but that check does not work with other languages and characters.

    The solution? Replace it with if(!is_numeric($a)){

    and that’s it!

    Thread Starter cicini

    (@cicini)

    It works. Thank you!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Users can get answers to questions from HTML’ is closed to new replies.