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] = [email protected]
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('[email protected]'),
    '#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

0

1 Answer 1

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."),
);
1
  • 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). Mar 4, 2016 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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