New question type plugin based on essay question type

New question type plugin based on essay question type

by Евгений Мамаев -
Number of replies: 5
Picture of Plugin developers

Hello!

I am developing a new question type plugin based in essay question type. The difference is that I need to implement 2 and maybe more textarea fields for answers. I have setup additional settings and now it displays 2 textareas  for answers.

Now how can I save those answers in database? I click save button in preview mode and all my textareas get empty

Average of ratings: -
In reply to Евгений Мамаев

Re: New question type plugin based on essay question type

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The most likely explanation is that you forgot to override the get_expected_data method. See the comment here https://github.com/moodle/moodle/blob/a672f021eaf0640c6f3b0094839c8c4fd3b2df7a/question/type/questionbase.php#L282, and look at what some of the standard question types do.
In reply to Tim Hunt

Re: New question type plugin based on essay question type

by Евгений Мамаев -
Picture of Plugin developers
Thank you, I have looked at code and have overridden get_expected_data method.
Now it has the following code

$expecteddata=array();
$expecteddata['paragraph1']=PARAM_RAW_TRIMMED;
$expecteddata['paragraph2']=PARAM_RAW_TRIMMED;

return $expecteddata;

I can see, that these parameters get submitted as

Content-Disposition: form-data; name="q26:1_paragraph1"

123
-----------------------------59511202423693
Content-Disposition: form-data; name="q26:1_paragraph2"

456

Is there a method to get these values, check them prior to store them?
In reply to Евгений Мамаев

Re: New question type plugin based on essay question type

by Евгений Мамаев -
Picture of Plugin developers
What $inputname should be passed in this call?
$qa->get_submitted_var($inputname, PARAM_RAW_TRIMMED);

Should it be "paragpaph1" or should it be dynamic "q26:1_paragraph1"?