How to add html in confirmation messages

I want to add some html code in confirmation, thank you,etc... messages in a quiz. Is it possible?. 

I need to add a link to the next quiz if they pass the first one.

Thanks a lot

Miquel

0
0
Supporter votes Members of the Supporter Network can vote for feature requests. When the supporter network has generated sufficient funding for the top voted feature request it will normally be implemented and released. More about the H5P Supporter Network
BV52's picture

Hi Miquel,

Currently this is not possible with the contents. The good news is H5P is open source so you or anyone in the community can make their own changes. This document is a good starting point.

-BV52

OK. Thanks. I'm not a developer, but I'll take a look to the document.

Thanks again.

Miquel

BV52's picture

Hi Miquel,

I think this is a very nice suggestion and I hope someone from the community picks this up and create the feature for us :-)

-BV52

I tried to write a custom module with this code

<?php

function h5palter_h5p_semantics_alter(&$semantics, $library_name = NULL) {
  // Check if this is the Question Set type.
  if ($library_name !== 'H5P.QuestionSet') {
    return; // Nope, do not continue.
  }
 
  foreach ($semantics as $field) {
    // Go through list fields
    while ($field->type === 'list') {
      $field = $field->field;
    }
 
    // Go through group fields
    if ($field->type === 'group') {
      h5palter_h5p_semantics_alter($field->fields, $library_name); // Check your function name!
      continue;
    }
 
    // Check to see if we have the correct type and widget
    if ($field->type === 'text' && $field->name === 'feedback') {
      $field->widget = 'html';
    }
  }
}

It converts the feedback option in an HTML widget, but a warnings messages are showed when I save the content:

  • WARNING: INVALID ARGUMENT SUPPLIED FOR FOREACH() IN H5PCONTENTVALIDATOR->VALIDATEGROUP() (LINE 3601 OF MODULES/H5P/VENDOR/H5P/H5P-CORE/H5P.CLASSES.PHP).
  • WARNING: FIRST PARAMETER MUST EITHER BE AN OBJECT OR THE NAME OF AN EXISTING CLASS IN H5PCONTENTVALIDATOR->VALIDATEGROUP() (LINE 3649 OF MODULES/H5P/VENDOR/H5P/H5P-CORE/H5P.CLASSES.PHP).
  • WARNING: FIRST PARAMETER MUST EITHER BE AN OBJECT OR THE NAME OF AN EXISTING CLASS IN H5PCONTENTVALIDATOR->VALIDATEGROUP() (LINE 3649 OF MODULES/H5P/VENDOR/H5P/H5P-CORE/H5P.CLASSES.PHP).

and when the Quiz are finished the feedback message still showing as a plain text with the html tags.

Please, can you (or anybody) help me? 

thomasmars's picture

Hi, I'm not able to reproduce this. It looks like there's something wrong with your semantics, since the group sent to validation is not able to validate.
Can you tell us more about what you have included in your H5P content, and when this error occurs, and what you have done before that ?
I'm not sure how you're getting the error, but you can not modify the widget of the feedback text inside the RangeList if that is what you're trying to do, since it is already being rendered by the RangeList widget, which does not allow modifications to its fields. Sorry about that.

It might also be useful to know that you should supply all tags that should be rendered for a 'html' widget to validate.

Hi Thomas,

I have included a Question Set with a Multiple Choice Question in my H5P content. The error occurs when I save the content.

Yes, as you say, I'm trying to modify the widget of the feedback text inside the RangeList.  I want to insert html content instead of plain text  in feedback text. My idea is to insert a link depending on the final punctuation. Is it possible to do?  Can you help me? I think that it can be a nice and useful feature for another H5P users.

Thank you very much for your time and I wish you a very happy and nice 2018.

Miquel

P.S. I'm sorry, but I don't undestand what is the minning of this: "It might also be useful to know that you should supply all tags that should be rendered for a 'html' widget to validate" . 

 

 

thomasmars's picture

Hi, I don' think you'll be able to change the feedback text input field to have a wysiwyg editor without actually changing the RangeList widget, which is probably not what you want.

What you can do, if you just want to add a static link depending on what is in the semantics, you can use the h5p_filtered_params_alter() hook instead, this will allow you to alter semantics before they are displayed. You can then alter the feedback field in semantics and add a link there.

My line about supplying "tags" attribute, means that if you're changing the widget of a "text" type semantic to "html", you should also provide a list with the allowed "tags" for that field. See for instance https://github.com/h5p/h5p-blanks/blob/master/semantics.json#L30-L40.

I urge you to play around with the different hooks to see what is possible.

Best regards, Thomas