0

I want to extend the simple text the Webform module allows for radio buttons to include HTML markup.

The Drupal Options Markup module purports to add markup to the text for radio buttons. It does, but it also seems to be very buggy and causes missing index errors in the Webform module.

Hand coding seems to be a better option. Digging into hook_form_alter, I can see where the array is built.

Here is the question: How do add markup to the plain text of the #options array. From the forms api reference, the t function is used. Can I insert HTML into that?

   '#title' => t('Selected'),
   '#options' => array(
      0 => t('No'),
     1 => t('Yes'),

The result I want can be seen in the Illustration from webform options markup. enter image description here

2 Answers 2

1

You can't add html to the t() function. A quick (and maybe dirty way) is to just do something like this:

   '#title' => t('Selected'),
   '#options' => array(
      0 => t('No') . '<span class="markup">Markup</span>',
     1 => t('Yes') . '<ul class="markup"><li>Markup</li></ul>',
1
  • Thank you for the suggestion. But I want to add the markup to the options, not the title. (see the graphic in my original post for illustration).
    – sea26.2
    Feb 11, 2015 at 15:50
0

You can add html to the t() function but i do not like it and i think it is not recommended.

quoting @thumbson

The multiple checkboxes/radios field types do not support field_prefix or field_suffix, though #prefix or #suffix should be possible. However, given that he's trying to add HTML to each option rather than the field, I don't think this will work.

Maybe this can help to achieve what you want #field_prefix:

Description: Text or code that is placed directly in front of the textfield. This can be used to prefix a textfield with a constant string.

And #field_suffix

Description: Text or code that is placed directly after a textfield. This can be used to add a unit to a textfield.

2
  • The multiple checkboxes/radios field types do not support #field_prefix or #field_suffix, though #prefix or #suffix should be possible. However, given that he's trying to add HTML to each option rather than the field, I don't think this will work.
    – thumbson
    Feb 11, 2015 at 16:08
  • Yes, i just noticed that after posted, i edit the post. Feb 11, 2015 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.