Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • VariableSet() and variableget() in drupal

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 308
    Comment on it

    Creating a form which contains two text fields and a submit button.Main aim is to save data and get the sabed values when needed. variableset() and variableget() functions to store and retrieve data.

    /*
    * Create a form
    */
    function mymenu_settings(&$form_state)
    {
        $form['mymenu_settings_form']['email'] = array(
            '#type' => 'textfield',
            '#title' => t('Enter e-mail'),
            '#size' => 50,
            '#maxlength' => 255,
            '#description' => t('This is an email field'),
            '#default_value' => variable_get('email'),
         );
    
         $form['mymenu_settings_form']['address'] = array(
            '#type' => 'textfield',
            '#title' => t('Enter address'),
            '#size' => 50,
            '#maxlength' => 255,
            '#description' => t('This is an address field'),
            '#default_value' => variable_get('address'),
         );
    
        $form['mymenu_settings_form']['save'] = array(
            '#type' => 'submit',
            '#value' => t('Save'),
            '#submit' => array('mymenu_settings_form_save_submit'),
          );
    
      return $form;
    }
    
    /**
     * Submit mymenu_settings_form  save action.
     */
    function mymenu_settings_form_save_submit($form, &$form_state) {
        // if required to set a value that is to be used later on
         variable_set('email', $form_state['values']['email']);
         variable_set('address', $form_state['values']['address']);
         drupal_set_message(t('Saved'));
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: