0

How can I add child elements to a checkbox/radio element? I have the following code.

$form['search_product'] = array(
    '#type' => 'radio',
    '#title' => t('Product'),
);

$form['search_product']['search_attributes'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
        'name' => t('by Name'),
        'model' => t('by Model'),
        'catalog_no' => t('by Catalogue No.'),
        'manufacturer' => t('by Manufacturer'),
        'description' => t('by Description'),
    ),
);

"search_attributes" checkboxes don't show up on the form, and I have only one radio.

1
  • Do you want to show the 'search_attributes' checkboxes if 'search_product' is selected? Why you set it like a parent?
    – Shyghar
    Oct 18 '13 at 9:15
1

I don't believe you can make a radio button a "parent".

Here's an example of using radios, checkboxes, and fieldsets.

http://api.drupal.org/api/examples/form_example!form_example_states.inc/function/form_example_states_form/7

You might take a look at http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#container

Try removing search_attributes from search_product

$form['search_attributes'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
        'name' => t('by Name'),
        'model' => t('by Model'),
        'catalog_no' => t('by Catalogue No.'),
        'manufacturer' => t('by Manufacturer'),
        'description' => t('by Description'),
    ),
);
0

I faced the same problem. To get checkboxes to be rendered, i'd suggest you go about it like so:

$form['search_product']['search_attributes'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
        'name' => t('by Name'),
        'model' => t('by Model'),
        'catalog_no' => t('by Catalogue No.'),
        'manufacturer' => t('by Manufacturer'),
        'description' => t('by Description'),
    ),
);
$form['search_product']['search_attributes'] = form_process_checkboxes($form['search_product']['search_attributes']);

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.