Set value for CheckBox field - Form API

By default checkbox works with 1, 0 values to be checked, unchecked respectivly.

$form['custom_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => 'Title',
      '#default_value' => variable_get('custom_var'),
    );


you can use #return_value to set a desired value for the checkbox field is it is selected.

$form['custom_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => 'Title',
      '#return_value' => $key,
      '#default_value' => variable_get('custom_var'),
    );

Comments

Popular posts from this blog

How to Reset Root Password in Drupal 7 with phpMyAdmin

Drupal - Hiding field group and its Children