views:

348

answers:

3

Hiya,

I've been shifting through the drupal documentation and forums but it's all a little daunting. If anyone has a simple or straight forward method for adding fields to the Site information page in the administration section i'd really appreciate it.

As a background, i'm just trying to add user customizable fields site wide fields/values.

+4  A: 

In a custom module, you can use hook_for_alter() to add extra fields to that form. For example:

function my_module_hook_form_alter(&$form, $form_state, $form_id) {i
  if ($form_id == 'system_site_information_settings') {
    $form['my_module_extra_setting'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use my setting'),
      '#default_value' => variable_get('my_module_extra_setting', TRUE),
    );
  }
}

Anywhere in your code you need access to the saved setting itself, you can use the same call that's used to populate that form element's default value: variable_get('my_module_extra_setting', TRUE)

Eaton
Right - excuse my noobness :)1. Is the code you posted - ready to use? can i drop it in and it would work?2. Where does it go? the template.php file?3. I've done a workaround - Created a new content type and with CCK created all the variable i need. in the page.tpl.php file i call in all the fields that i had stored in that node - thus now any kind of variable i need easily accessible. Is this bad? I've redirected a link to that page using pathauto to the front page for security (not really required but just in case.
Shadi Almosri
As His Eatonness said, this code needs to go into a custom module. Since this function is a hook and starts with my_module, it belongs in a module with that name. Something like sites/all/modules/my_module/my_module.module. You will also need a sites/all/modules/my_module/my_module.info file to be able to enable the module.
mikl
A: 
max
+1  A: 

The function should be mymodule_form_alter instead of mymodule_hook_form_alter

Saggy