Jump to content

Formbuilder: allow html in label

Recommended Posts


I want to add a checkbox to my contact form to have users confirm that they have read the privacy policy before sending the form.
In the label of the Checkbox I want to add a link to the privacy statement page. But HTML isn't rendered, it apears as text output in the label.

How can I allow html in formbuilder checkbox labels?

Thanks for a hint.

Share this post

Link to post
Share on other sites

My thought is that you could use a hook  to add the html into the rendering of the Inputfield, or maybe you could add a Markup field in FormBuilder so you can place this link, right bellow the checkbox. 

Share this post

Link to post
Share on other sites

I usually use a simple checkbox and an adjacent Markup field with all the text and links and other BS(sorry). Works great and everybody can edit the text if necessary.


  • Like 1

Share this post

Link to post
Share on other sites

@Klenkes To accomplish this, you need to replace line 94 in InputfieldCheckbox.module

"<span class='pw-no-select'>" . $this->entityEncode($label) . "</span></label>";

with this:

"<span class='pw-no-select'>" . $label . "</span></label>";

but it isn't a good idea to modify core parts.

@ryan Is it possible that you remove the entityEncode from InputfieldSelect in the core, so we can use hyperlinks, classes,  etc. in the label, or are there any security concerns? What Klenkes describes is a common need here in Germany. The other solution using InputfieldMarkup isn't as good as this solution. 

However I think one could replace the render function of the InputfieldCheckbox.module with a hook, but it would be nicer to have this feature in the core.

What do you think?

Share this post

Link to post
Share on other sites

I tried to replace the InputfieldCheckbox render function with a hook in my `_init.php`but it did not work. I get the error in the screenshot below.

Here is my hook function:

$this->addHookAfter('InputfieldCheckbox::render', function ($event) { // outside a class
//    $page = $event->object;
//    if ($page->template == 'admin') return;
    // tell ProcessWire we are replacing the method we've hooked
    $event->replace = true;

    $label = '';
    $user = wire('user');
    if ($user->language) $label = Inputfield::getSetting("checkboxLabel$user->language");
    if (!$label) $label = Inputfield::getSetting("checkboxLabel");
    if (!$label && $this->checkedValueIsLabel) $label = $this->checkedValue;
    if (!$label) $label = Inputfield::getSetting('label2');

    $this->set('skipLabel', $this->description || $label ? Inputfield::skipLabelFor : Inputfield::skipLabelHeader);
    if (!$label) $label = $this->label;

    // TBA: if($this->uncheckedValue) return $this->renderRadio();

    $attrs = Inputfield::getAttributes();
    $attrs['value'] = $this->checkedValue;

    $out =
        "<label><input type='checkbox' " . Inputfield::getAttributesString($attrs) . " />" .
        "<span class='pw-no-select'>" . $label . "</span></label>";

    $event->return = $out;



Share this post

Link to post
Share on other sites

Well, had to do this now for including a privacy policy link in a formbuilder label 🙂

    $field = $event->object;
    $output = $event->return;
    $policyUrl = $this->pages->get("name=privacy-policy")->url;
    if($field->name == "privacy_policy"){
        $output = str_replace("privacy policy","<a href='{$policyUrl}'>privacy policy</a>", $output);
    $event->return = $output;    


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...