How to add HTML in forms label

jakubmis
Member | 1
+
0
-

Hi,

I am trying to create form with GDPR agreement. I added checkbox for that but now I need to link the label of this checkbox to the GDPR page. How can I do that?

my current code is

$form->addCheckboxList('gdpr', 'GDPR', ['gdpr' => 'I agree with GDPR'])->setRequired();
David Matějka
Moderator | 6445
+
0
-

Hi, you can use Nette\Utils\Html instance as a label:

$form->addCheckboxList('gdpr', Nette\Utils\Html::el('a')->href(...)->setText('GDPR'), ['gdpr' => 'I agree with GDPR'])->setRequired();

you can also use it as a label of individual checkbox list items.

(btw, are you sure you need Checkbox list? isn't basic checkbox sufficient?)

more info in doc: https://doc.nette.org/…tml-elements

MajklNajt
Member | 471
+
0
-

Hi, in this case I would choose single checkbox (as David suggested)

$form->addCheckbox('gdpr', 'I agree with GDPR')->setRequired();