Checkboxes: how do I set the default values or show the user defined values using Form API? I am using an checkboxes element within a form in module that I started developing for Drupal 7. This is my first attempt at module development and using the Form API. I am creating a list of checkboxes that list down all the content types of a specific site. An array of all the content types can be obtained by using the following: $nodeTypesRaw=node_type_get_names();. An array with the machine names of the content types as the keys and the human readable names as the values are obtained.

By default, I would like all the checkboxes to be selected and when the form is submitted. How do I achieve that? The Form API pages on the drupal site aren't very helpful with regards to setting the default values for checkboxes. 

$nodeTypesRaw=node_type_get_names();
$nodeMachineNames=array_keys($nodeTypesRaw);
$form['process_comments']['custommod_published_comments_select_node_types']['custommod_published_comments_node_types_checkboxes']=array(
          '#deafult_value'=&gt;$nodeMachineNames,
          '#options'=&gt;$nodeTypesRaw,
          '#type'=&gt;'checkboxes',
);


I initially started out with the above code, but it won't work. It does display the list of checkboxes, but they are not checked by default. The variable does get on form submission though (checked via drush and var_dump).
From Drupal.org:

$form['element_id'] = array(
  '#type' =&gt; 'checkboxes',
  '#options' =&gt; array(1 =&gt; "One", 2 =&gt; "Two", 3 =&gt; "Three"),
  '#default_value' =&gt; array(1, 3),
);


Default value is set as an array representing keys of selected options.

Looking at the code in your question, problem is with spelling. you are setting '#deafult_value' when you want to set '#default_value'.