Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6654227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:21:54+00:00 2026-05-26T01:21:54+00:00

I am setting up a configuration page for a new module and I am

  • 0

I am setting up a configuration page for a new module and I am having trouble getting my textfield to remember data I previously entered.

I am setting #default_value by calling variable_get but the value never gets reset in the textfield. It is however correctly stored as a variable and visible on the variable editor page.

Below is a code fragment:

$form   =   array();

$form['username']   =   array(
    '#type'                     =>  'textfield',
    '#title'                    =>  t('Username'),
    '#default_value'            =>  variable_get('username', '' ),
    '#description'              =>  t('supply the username'),
    '#maxlength'                =>  30,
    '#required'                 =>  TRUE,
    '#weight'                   =>  -1,
);

return system_settings_form($form);

How can I fix this?

Updated code

The submit function is as follows:

    function mymodule_settings_submit($form, &$form_state){
    drupal_set_message('form submit responding : ' . $form_state['values']['username'] );
    variable_set( 'username', $form_state['values']['username'] );
}

Updated code #2

The full code:

    function my_module_init(){
}

function my_module_menu(){

    $items = array();
    $items['admin/settings/helper'] =   array(
        'title'                     =>  'helper',
        'page callback'             => 'drupal_get_form',
        'page arguments'            =>  array('helper_setup'),
        'access arguments'          =>  array('access administration pages'),
        'type'                      =>  MENU_NORMAL_ITEM,

    );
    return $items;

}

function helper_setup(){

    $node_types =   node_get_types('names');

    $form   =   array();

    $form['username']   =   array(
        '#type'                     =>  'textfield',
        '#title'                    =>  t('Username'),
        '#default_value'            =>  variable_get('username', '' ),
        '#description'              =>  t('supply the username'),
        '#maxlength'                =>  30,
        '#required'                 =>  TRUE,
        '#weight'                   =>  -1,
    );

    $form['#submit'][] =    'my_module_settings_submit';

    return system_settings_form($form);
}

function my_module_validate($form, &$form_state){
    die('validation area responding!');
}

function my_module_settings_submit($form, &$form_state){
    drupal_set_message('form submit responding : ' . $form_state['values']['username'] );
    variable_set( 'username', $form_state['values']['username'] );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:21:55+00:00Added an answer on May 26, 2026 at 1:21 am

    in your form submit function you should insert variable_set('variableName' , 'value') variables is not inserted automatically..

    UPDATE:

    $form['username']   =   array(
        '#type'                     =>  'textfield',
        '#title'                    =>  t('Username'),
        '#default_value'            =>  variable_get('username', '' ),
        '#description'              =>  t('supply the username'),
        '#maxlength'                =>  30,
        '#required'                 =>  TRUE,
        '#weight'                   =>  -1,
    );
    
    $form['#submit'][] = '_myform_submit_function' ; 
    return system_settings_form($form);
    

    now lets build your submit function

    function _myform_submit_function($form,&$form_state ) {
    variable_set('username', $form_state['values']['username']) ; 
    drupal_set_message('form submit responding : ' . $form_state['values']['username'] );
    }
    

    now clear the cache and tell me if its working or not

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a .NET project, say you have a configuration setting - like a connection
I'm setting up a User Control driven by a XML configuration. It is easier
Seems like this should be easy, but I'm not finding a simple configuration setting.
Setting the src attribute of an IFrame to data:application/pdf;base64, isn't working for me, any
I am currently setting up my New Mac Mini Lion server. I am now
I'm in the prcoess of setting up my (Wordpress) solution on a new production
Just migrated to a new machine and having issues. Note: This is a Windows
string [] files = new string[2]; files[0] = ThinkFarAhead.Example.Settings.Configuration_Local.xml; files[1] = ThinkFarAhead.Example.Settings.Configuration_Global.xml; //Resharper complains
If I put configuration settings (like membership provider) DB Connnection, etc. in the machine.config,
I need to pass configuration settings to an AddIn created using the Managed AddIn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.