HD Quiz

Import MULTIPLE correct answers / Questions with type “All that apply: text”

Published: November 8, 2024
Support status: closed

We still have to add loads of questions via CSV.

Some questions are Questions with type “All that apply: text”…
How to organise the multiple answers via CSV Uploads?
How to declare the question to the fitting question type?

Until now we uploaded question…all answers…and then MANUALLY added second correct answer…and fixed question types….no problems.

Now i have 3000 Questions…and im looking to DIRECT make them right question type and give the multiple correct answers when CSV uploading…

Any ways for this?

thread author: Sören Hartwig

Hi again Sören,
I deleted your other thread “BULK change question type ?” since it’s a similar question — or will have a similar answer at least to this one.

Surprisingly, I had a very similar question last week that can be read here:

https://wordpress.org/support/topic/csv-features-importing-questions/

The short of it is that in the current version of HD Quiz ⇾ this is impossible. All questions use the default question type, with only one possible selected answer. You have to manually update the questions to change from there.

The reasoning is basically supporting on my end. I deal with so many support requests about the importer — and the answer to almost all of them is “you improperly formatted your CSV file”.

From a technical standpoint, it would be easy for me to allow you to select an “array” of correct answers. The problem is the massive influx of support requests I’d get from users who don’t understand how to format the answers and need help with it.

Solutions

No code
If you are not comfortable adding or editing any code, I can recommend checking out the new beta 2.0 of HD Quiz (it should work beautifully, but I recommend backing up your database just in case you have a problem and need to revert to the current 1.8.15 version).

The reason I recommend this is that unlike the current version of HD Quiz, the new 2.0 version allows you to open multiple quizzes and questions in new tabs. Don’t get me wrong, updating over 3000 questions will still be incredibly annoying and tedious, but the ability to open up several questions in tabs at once should significantly improve the time it’ll take to get all of it done.

Requires code
if you are comfortable with editing some code, then you can edit the tool function directly. If you edit hd-quiz/includes/tools/csv_importer.php, on line 241 you will see $fields["question_type"]["value"] = "multiple_choice_text";.

Change multiple_choice_text to select_all_apply_text and bam! Questions will now be imported as the select all that apply type.

But that won’t be enough, because we also need to tell the importer which answers are the correct ones.

On line 239 you will see $fields["selected"]["value"] = array($csvAsArray[$start][12]);. This is where we save the correct answer.

You will need to change array($csvAsArray[$start][12]); to explode("|", $csvAsArray[$start][12]);

This will take that field, and separate the correct answers with a | symbol.

This also means that your CSV will need to be updated to set the “Correct answer” field from a simple integer, to a list of correct answers separated with the |. For example, 1|3|4 would set the first, third, and fourth answers as correct.

If you decide to go this rout, I DEMAND that after you make these edits, you test with a CSV containing a single question. This is to make sure the edits work before committing to the full import.

EDIT: You will also need to delete the lines 187 to 190 to stop the correct answer field from being sanitized as an integer.

08 November 2024 — 16:14 support admin - Dylan

Hello Dylan…

thanks for this insight…

i completly understand your point… i got my 3000 questions plus answers already in a desasterous organised way from my client… :D:D:D because the didnt understand putting values in tables…not even on csv standart :D:D:D

What u wrote hepls me a lot…i can reduce a bit workload stupidity…

my gloabal problem is, i get a list of question that is MIXED…some are single answer…some are multiple answer…so a global change of the imported class is only semi-helpful… since then ALL questions become multichoice…also teh single choice ones…and this are the majority…

This would only make sence if i could import BOTH types via same csv… defining the question type for each question via the csv…

08 November 2024 — 16:40 thread author - Sören Hartwig

I’d recommend creating two separate CSVs.

One that only contains the default multiple choice, and one that contains the select all that apply.

Upload the first CSV with default HD Quiz. Then make the above changes and upload the second CSV.

08 November 2024 — 16:45 support admin - Dylan

yes…i gonna split my 7 csv into 14 separated… at least i save a bit of lifetime… 😉

08 November 2024 — 17:21 thread author - Sören Hartwig

Respond to thread

This thread has been closed / marked as resolved.
You can reply to this thread, but it might be better to start a new thread if you need help
.

You can also upload images to imgur and paste the links here. Just make sure that your images don't include any sensitive information.

Submit