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'=>$nodeMachineNames,
'#options'=>$nodeTypesRaw,
'#type'=>'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).
#default_value
, not#deafult_value
. FA not AF.