2

I created custom settings for my theme for storing email, fb url, twitter url and g+ url. Everything is coming properly but the settings are not getting saved. I have no idea whats wrong. All the code and screenshots are below.

.info file content

settings[z_email] = mail@zed.com
settings[z_facebook] = fb/url
settings[z_twitter] = twitter/url
settings[z_gplus] = gplus/url

theme-settings.php file content

function z_form_system_theme_settings_alter(&$form, $form_state) {
  $form['z_email'] = array(
    '#type'          => 'textfield',
    '#title'         => t('Email'),
    '#default_value' => theme_get_setting('mail@zealind.com'),
    '#description'   => t("Global Email Id for ZealInd site."),
  );

  $form['z_facebook'] = array(
    '#type'          => 'textfield',
    '#title'         => t('Facebook'),
    '#default_value' => theme_get_setting(''),
    '#description'   => t("Facebook Url."),
  );

  $form['z_twitter'] = array(
    '#type'          => 'textfield',
    '#title'         => t('Twitter'),
    '#default_value' => theme_get_setting(''),
    '#description'   => t("Twitter Url."),
  );

  $form['z_gplus'] = array(
    '#type'          => 'textfield',
    '#title'         => t('Google+'),
    '#default_value' => theme_get_setting(''),
    '#description'   => t("Google+ Url."),
  );



}

The theme setting page:

enter image description here

8

You're not using theme_get_setting() quite right at the moment; the first argument should be the name of the setting, not a default value.

For example, your element defined as $form['z_email'] should look like this:

$form['z_email'] = array(
  '#type'          => 'textfield',
  '#title'         => t('Email'),
  '#default_value' => theme_get_setting('z_email'),
  '#description'   => t("Global Email Id for ZealInd site."),
);
| improve this answer | |
  • 1
    This seems to be a little bit misleading. Actually the form inputs are getting saved successfully without any '#default_value', but you need to set it to theme_get_setting('setting_foo') to display it (as input value). – Philipp Michael Mar 4 '16 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.