How to add HTML in forms label

10 days ago

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();

10 days ago

David Matějka
Moderator | 5609
+
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

9 days ago

MajklNajt
Member | 48
+
0
-

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

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