views:

12

answers:

1

How can I specify a default value and hide this checkbox ?

[states] => Array
        (
            [#type] => checkboxes
            [#title] => Status
            [#options] => Array
                (
                    [active] => Active users
                    [inactive] => Inactive users
                )

            [#description] => Subscriptions matching the selected states will be exported.
            [#required] => 1
        )

I've tried

$form['states']['#default_value'] = 'active';

but it gives me an error.. thanks

A: 

Your code as written will produce a syntax error, since you're declaring the 'states' array wrong. This is a PHP syntax thing that doesn't really have anything to do with Drupal's forms API.

Try:

$form['states'] => Array (
  '#type' => 'checkboxes',
  '#title' => t('Status'),
  '#options' => Array (
    'active' => 'Active users',
    'inactive' => 'Inactive users',
   ),
   '#description' => t('Subscriptions matching the selected states will be exported.'),
   '#required' => 1,
   '#default_value' => 'active',
);

Unrelated to the syntax issue, a better way to do this would be to reset the entire form element as a '#type' = 'value'. For example $form['states']['#type'] = 'value'; $form['states']['value'] = 'whatever'

anschauung

related questions