Drupal 7 - data not being saved into the variable table when using system_settings_form to handle forms

If you use the Drupal system_settings_form function to have Drupal handle saving data into variables, make sure that the form element array key matches the name of your variable. Checking for any misspellings before going into any further debugging may save you a lot of time.

$form['form_settings_example'] = array(
    '#type' => 'select',
    '#title' => t('Choose one of the following options'),
    '#default_value' => variable_get('form_settings_example', 1),
    '#options' => array(
      1 => t('First option),
      2 => t('Second option'),
      3 => t('Third option'),
    ),
    '#multiple' => false,
);

In the example above the array key in line 1 is form_settings_example and the name of the variable in line 4 matches the array key. It won't work if they do not much.

Comments

Thanks a looooot. Same

Thanks a looooot.
Same problem, you save my day :P

oh my God! For a few hours I

oh my God! For a few hours I thought I was going mad... Thanks for the post.

I'm quite plsaeed with the

I'm quite plsaeed with the information in this one. TY!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

5 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.