I would like to save the form field values by using mymodule_admin(). How can I get the values saved in mymodule_admin() on the other form without using the database?

function subscription_admin() {
  $form = array();
  $form['txtSubscription'] = array(
        '#type' => 'textfield',
        '#title' => t('Enter The Subscription Amount'),
        '#default_value' => variable_get('txtSubscription', '500'),
        '#size' => 20,
        '#maxlength' => 20,
        '#description' => t('This text field tells the subscription generation amount'),
        '#required' => TRUE,
return system_settings_form($form);

This is the admin view form. If the administrator user changes the value, it would be changed.

  • As per my understanding you have retrieve the value which is entered in subscription_admin() correct? – Ramesh Babu T B Mar 21 '13 at 9:18
  • yeah!! you are right !! – Sridhar Ramakrishnan Mar 21 '13 at 9:26
  • use the below answer is correct by using variable_get – Ramesh Babu T B Mar 21 '13 at 9:41

mymodule_admin() is not the function that does the trick saving your variables. It's system_settings_form().

You can retrieve variables saved by system_settings_form() using variable_get() function. So, in your case, you can get the value like this:

$txtSubscription = variable_get('txtSubscription', '');

Second parameter of the variable_get function will be returned if the variable is not set (not necessarily empty). Notice that we used the same key as your form array's key.

During the Drupal bootrap, all variables are loaded to $GLOBALS (Thanks to kiamlaluno for the correction). Do not use this to store all your data because all of these variables will be loaded on every bootstrap.

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.