is it possible to add a simple html link in the label/title of a checkbox? I tried the following code:
<?php
$form['legal']['#type'] = 'checkbox';
$form['legal']['#required'] = TRUE;
$form['legal']['#title'] = t(
'You must accept our @tos and @legals',
array(
'@tos' => l(t('terms of service'), 'node/6'),
'@legals' => l(t('legals'), 'node/7')
)
);
?>
But that produces the follwing label (the html markup isn't "translated"):
"You must accept our < a href="/node/6">terms of service< /a> and < a href="/node/7">legals< /a> *"
(I've added spaces after the opening brackets so that it will not be converted to the link i want to have)
Is it not possible to do such things? I Am new to drupal. Perhaps somebody can help me... Thanks!
Instead you can try to use #prefix
.
$form['legal']['#prefix'] = t(
'You must accept our @tos and @legals',
array(
'@tos' => l(t('terms of service'), 'node/6'),
'@legals' => l(t('legals'), 'node/7')
)
);
Hope this works... Muhammad.
This happens before you force the text to be printed as plain text.
<?php
$form['legal']['#type'] = 'checkbox';
$form['legal']['#required'] = TRUE;
$form['legal']['#title'] = t(
'You must accept our !tos and !legals',
array(
'!tos' => l(t('terms of service'), 'node/6'),
'!legals' => l(t('legals'), 'node/7')
)
);
?>
Note that you are using t() function, which acts differently on replacement's prefix.
If you put @tos
, it will be run through check_plain() so HTML will never be processed by the browser as it encodes HTML entities.
!tos
allows HTML markup as it will not be check_plain()
'd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With