2

I wanted to change id of radio button. But i dont know which attribute shall i use to do that.

$form['entry.497535900'] = array(
'#type' => 'radios',
'#title' => t('Category'),
'#options' => array('P' =>'Product','S' => 'Services','O' =>'Others'),

);

2 Answers 2

2

If you need to assign IDs to each radio option, then you can use custom theme function, to theme your radios. See example:

$form['entry.497535900'] = array(
  '#type' => 'radios',
  '#title' => t('Category'),
  '#options' => array('P' =>'Product','S' => 'Services','O' =>'Others'),
  '#theme' => 'mymodule_custom_radios',  
);

The #theme parameter specifies function, which overrides the default radios styling function. You will need to define this function in hook_theme() and create the content of the function, where you can specify, how radios should be rendered.

/**
 * Implements hook_theme.
 */
function mymodule_theme($existing, $type, $theme, $path) {
  return array(
    'mymodule_custom_radios' => array(
      'arguments' => array('element' => NULL),
    ),
  );
}

Then create the content of this function.

function theme_mymodule_custom_radios($element) {
  // You can access all radios options like this - $element['#options'];

  $output = '';
  // ... create html output according to your needs
  return $output;
}
0
1
'#attributes' => array(
    'id' => 'your-id',
 ),

You need use "#attributes".

4
  • but for each radio buttion how can set id. Mar 1, 2016 at 11:01
  • for every radio button its cumming same..i want different different id for each radio button..plz help if know about this or any resource will be very helpful Mar 1, 2016 at 11:05
  • what is the need to set id for each items?
    – DRUPWAY
    Mar 1, 2016 at 11:09
  • i am sending data to google form..and google cheking id to fetch specific radio button data. Mar 1, 2016 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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