1

I'm altering the following form, admin/config/system/site-information.

I need a textbox in the site details section, below the email address textfield. The name of the textbox should be site_organisation. This textbox needs to save to variable when the save configuration button is clicked. Its saved value should be displayed when the page is reloaded.

How can I do this? Is there a module that can do this?

4

You need to add your own module if you're looking to alter this form. You'll need 2 things:

  1. An alter form hook function to add the text field.
  2. A submission handler to process the data.

Something like this...

function mymodule_form_system_site_information_settings_alter(&$form, $form_state, $form_id) {
  $form['site_information']['mymodule_site_organisation'] = array(
    '#type' => 'textfield',
    '#title' => t('Site Organization'),
    '#default_value' => variable_get('mymodule_site_organisation', ''),
  );
  $form['#submit'][] = 'mymodule_handler';
}
function mymodule_handler($form, &$form_state) {
  variable_set('mymodule_site_organisation', $form_state['values']['mymodule_site_organisation']);
}

Once implemented, you can reference your custom value by using variable_get('mymodule_site_organisation', '') anywhere you need it.

0

Consider editing your question to explain "why" you would want to alter that form, add that field "site_information", etc. The way the question is phrased right now, I have the impression that you're making it way too complicated to address something that is rather easy to do with some standard Drupal features.

If you only want to "display the 'site organisation' when the page is reloaded" (or whatever other info you'd want to enter in such textbox) Then it may be sufficient to create a new block, position it in the right spot (region) of the theme you're using (optionally with some extra CSS / theming stuff to make it pixel perfect). And with the content of the block equal to what you mean with "the value entered in this textbox". That would also avoid you'd have to enable yet some other module in your site (cfr. the "which module to use for that).

Or is there some other reason why you really want this to be done via such variable as you asked about?

PS: I just saw Shawn's answer also, which is obviously a great answer (I think) if you really want/need to go that route (for reasons however that right now I cannot find in your question). To actually decide about which of these 2 answers to go for, it might depend also on:

  1. preferences or skills of either the person in charge of building the site, like a Drupal developer, a site builder, someone new to Drupal, etc, or

  2. the actual customer that the site is for, who would have to choose between a custom module and some rather basic Drupal admin feature that requires less skills to keep up to date.

0
if ($form_id == 'system_site_information_settings') {
   // echo '<pre>'; print_r($form); echo '</pre>'; exit();
   $form['site_information']['site_organisation'] = array(
     '#title' => t('Site Organisation'),
     '#description' => t('Site Organisation'),
     '#type' => 'textfield',
     '#default_value' => !empty(variable_get('site_organisation')) ? variable_get('site_organisation') : '',
   );
 }
  • 1
    Just posting some code here without any explanation is not consider a good answer around here ... Please edit your answer to explain how it answers the question (I just edited it to at least "format" that code to make it readable) ... Just trying to get you going on this site, OK? – Pierre.Vriens Apr 21 '16 at 12:49

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.