Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7: Checkbox label with links in it

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!

like image 843
mAtZ Avatar asked Nov 01 '12 18:11

mAtZ


2 Answers

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.

like image 35
Muhammad Reda Avatar answered Sep 19 '22 00:09

Muhammad Reda


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.

like image 159
AKS Avatar answered Sep 21 '22 00:09

AKS