I am trying to create a set of radio buttons that have a link associated with them. This link will popup a secondary window to show the user some information. The radio buttons are created from data brought out of a database.

What is currently happening is that the link that is getting creating is also selecting the radio button. I want this link to be associated with the radio button item but not actually allowed to select the button when clicked.

My question is: How do I add a link to a radio button element, that does not allow the radio button to be selected when the link is clicked.

  $form['Classes']['Classes'] = array(  
    '#type' => 'radios',
    '#title' => t('Course Date / Location'),
    '#required' => TRUE,
    '#options' => $rows
  );

here is the definition of the radios type.

The $rows is the information that is created as an array beforehand. I'm currently putting all information into the array. How do I add individual information for each radio button that is a link. This list depends on when it was looked at. If it was looked at in January there would be more information that if it was looked at in February. All the January classes would lot be listed.

Thanks

Comments

mooffie’s picture

I'd suggest theming the radios in a table. Something along of:

Course            Date/Location          More Info

(.)   Maths       Jun next year          [link]
(X)   Sewing      After the holidays     [link]
(.)   Origamy     My backyard            [link]
jon_kump’s picture

what would be the best way of theming that. I like the idea. I think it would work out nicely.

Would I just do the following

$form['Classes']['Classes'] = array( 
    '#type' => 'radios',
    '#title' => t('Course Date / Location'),
    '#required' => TRUE,
    '#options' => theme('table', $rows)
  );

instead of the old

$form['Classes']['Classes'] = array( 
    '#type' => 'radios',
    '#title' => t('Course Date / Location'),
    '#required' => TRUE,
    '#options' => $rows
  );
mooffie’s picture

Would I just do the following
...
'#options' => theme('table', $rows)

No, you build the form normally. The theming you do by pointing Drupal, via the '#theme' attribute, to your theming function.

There are several places in Drupal core where radios, or checkboxes, are displayed in a table. One such place is q=admin/settings/filters

There are some examples in the handbooks about theming forms. About tables in particular there's http://drupal.org/node/47582 (See 'dayre's comment).

Here's a simpleminded example I just wrote:

$form['courses'] = array(
  '#type' => 'radios',
  '#options' => array(
    101 => 'Math',
    102 => 'Gardening',
    103 => 'Origamy',
  ),
  '#theme' => 'mycourses',
);

....

function theme_mycourses(&$form) {
  foreach (element_children($form) as $key) {
    $row = array(drupal_render($form[$key]),
                'My backyard',
                'some link');
    $rows[] = $row;
  }
  $output .= theme('table', array(t('Course'), t('Where'), t('More')), $rows);
  $output .= drupal_render($form);
  return $output;
}

I hard-coded the 'My backyard' etc., because I don't have the time right now for something fancier, so my exmpale is quite crippled. It's just to give you some general idea. Usually you put this extra data in some other form array, as dayre shows at the page I linked to.

jon_kump’s picture

Thanks mooffie,

That worked out great. Exactly what I was looking to do.

Regards