HTML in webform labels

by Alexei Rayu   Last Updated June 30, 2020 03:07 AM - source

I need to insert HTML markup (spans, classes, h2 tags). However, webform appears to be filtering out all markup from labels. Has anybody succeeded in inserting html markup in labels, and how did you do that?

Tags : webforms theming


Answers 3


You won't be able to use HTML markup within the label inputs within the Webform module itself, as it most likely cleans out all HTML markup before displaying to the user to prevent XSS attacks etc.

Most likely you'll need to write a small custom module which implements hook_form_alter, which will allow you to change the markup used for the labels.

I'm not actually sure if Drupal will allow markup within the #title attribute of your form elements, so you might need to use the #prefix property instead to add your custom HTML replacement labels.

If this is all Greek to you then you'll probably need to checkout these tutorials:

Creating modules - a tutorial: Drupal 7.x

Hook snippets: hook_form_alter

Alex Kirsten
Alex Kirsten
February 21, 2014 12:40 PM

the "Options with Markup" module allows HTML formatting of labels for radio button/checkbox.https://www.drupal.org/project/webform_optionsmarkup

rvb
rvb
February 05, 2015 16:50 PM

I added the following to the bottom of my settings.php page. I read it somewhere... works like a charm. :)

$conf['webform_allowed_tags'] = array('a', 'em', 'strong', 'code', 'img', 'ul', 'li', 'u', 'span style="font-style:italic', 'span' , 'a', 'i', 'italic');  
Mwow
Mwow
June 30, 2020 02:15 AM

Related Questions


Custom confirmation modal with webform inDrupal 8

Updated April 24, 2018 15:07 PM



Template based on machine name

Updated September 24, 2018 15:07 PM