Drupal - How to check a checkbox by default in forms api

See below example...

$options = array();
$options["1"] = "One";
$options["2"] = "Two";
$options["3"] = "Three";
$options["4"] = "Four";


$form['ios'] = array(
  '#title' => t(''),
  '#type' => 'checkboxes',
  '#description' => t(''),
  '#options' => $options,
  '#default_value' => array("1", "2", "3")
); 

You Have Single Field like News letter or terms condition check box , You can use below code

 $form['name']['terms_condition'] = array(
      '#type' =>'checkbox',
      '#title'=>t('Terms and conditions'),
      '#required'=>TRUE,
      '#default_value' =>TRUE, // for default checked and false is not checked
  );

Tags:

Forms