Checked checkboxes after form submit i have a basic admin form, which shows all content types with checkboxes and save button:

function MYMODULE_admin_settings() {
    $types = node_type_get_types();

    $form['content_types'] = array(
        '#type' =&gt; 'fieldset',
        '#title' =&gt; t('Content types'),
        '#description' =&gt; t('test'),
        '#collapsible' =&gt; TRUE,
        '#collapsed' =&gt; TRUE,
    );
    foreach ($types AS $typename =&gt; $type) {
        $form['content_types'][$typename] = array(
            '#type' =&gt; 'checkbox',
            '#title' =&gt; $type-&gt;name,
        );
        }
        $form['submit'] = array(
            '#type' =&gt; 'submit',
            '#value' =&gt; t('Submit'),
        );
        return $form;

}


When i submit i want to save checked content types somewhere(i don't know what is the best way - save to database or somewhere else like variable_set). And the question is how to show checked content types after submit form - #default_value. For example if i check Article and Basic page c.types submit it and save them to db i want to see them checked after page reload, how can i do this?
Most core (and contrib) modules make use of the system_settings_form() function which handily wraps around a form, and saves element values as variables automatically.

function MYMODULE_admin_settings() {
  $types = node_type_get_types();

  $form['content_types'] = array(
    '#type' =&gt; 'fieldset',
    '#title' =&gt; t('Content types'),
    '#description' =&gt; t('test'),
    '#collapsible' =&gt; TRUE,
    '#collapsed' =&gt; TRUE,
  );
  foreach ($types as $typename =&gt; $type) {
    $form['content_types']["MYMODULE_settings_$typename"] = array(
        '#type' =&gt; 'checkbox',
        '#title' =&gt; $type-&gt;name,,
        '#default_value' =&gt; variable_get("MYMODULE_settings_$typename", 0)
    );
  }
  $form['submit'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Submit'),
  );

  return system_settings_form($form);

}


You can then grab the value anywhere else in code like this (using the 'page' content type as an example):

$val = variable_get('MYMODULE_settings_page');


Which is a bit counter-intuitive. You might want to make use of a checkboxes type instead, e.g.

$options = array();
foreach ($types as $typename =&gt; $type) {
  $options[$typename] = $type-&gt;name;
}
$form['content_types']['MYMODULE_content_types'] = array(
  '#type' =&gt; 'checkboxes',
  '#title' =&gt; $type-&gt;name,
  '#options' =&gt; $options,
  '#default_value' =&gt; variable_get('MYMODULE_content_types', array())
);


Then you can get an array of all selected content types like this:

$selected_types = array_filter(variable_get('MYMODULE_content_types', array()));