0

I got the following issue. A clients wants that the text after checkboxes are links to other pages and thus between ...

I have the following code:

$form['boxes_brands'] = array(
    '#type' => 'checkboxes',
    '#title' => '<div id="title-container">Merken</div>',
    '#options' => $brandArr,
    '#default_value' => $_SESSION['filter_brands_cat'],
);

$brandArr is an array of brands.

I looked in the Form API of Drupal but I did not find an option to do this. I could alter the values in $brandArr but of course that changes the value of the value attribute of the input object too.

Using the prefix and suffix options won't work either because I don't want the checkboxes in the tags too.

Is there a clean way to do this?

1

You can give the $options as an array of value and label. And the label can then be given as a link using l().

'#options'       => array(
  'facebook'     => l(t('Facebook'), 'http://www.facebook.com'),
  'twitter'      => l(t('Twitter'), 'http://www.twitter.com'),
),
  • via @BobKline The problem with this answer is that some browsers (e.g., IE9) will bubble up the click event for the link to the checkbox, so when the user returns to the tab with the form she finds that the state of the checkbox has changed. It's not clear that this behavior isn't the correct behavior for event propagation, but it's surely not the effect the OP had in mind. – mpdonadio Mar 9 '13 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.