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 6846777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:39:54+00:00 2026-05-27T00:39:54+00:00

I am trying to do a variable_set() when clicking ‘Reset default values’ on my

  • 0

I am trying to do a variable_set() when clicking ‘Reset default values’ on my module’s admin page form. This runs through system_settings_form_submit(). The #default_value inside my form is reset, but my module relies on this stored variable to display some data. Clicking reset fills in the form with the default, but does not ‘Save’ it to recreate the variable in the database, so my module’s function breaks. It appears that nothing happens after clicking Reset, other than it deleting the variable from the database. Thanks in advance.

My submit function looks like this:

function faculty_submit(&$form, &$form_state){
  if($form_state['values']['op'] == 'Reset to defaults') {
    global $faculty_detail_template_default;
    variable_set('faculty_detail_template', $faculty_detail_template_default);
  }
  elseif ($form_state['values']['op'] == 'Save configuration') {
  // Clear caches for list and detail pages.
  cache_clear_all('faculty_list', 'cache', TRUE);
  cache_clear_all('faculty_detail_load', 'cache', TRUE);
  }
}
  • 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-27T00:39:55+00:00Added an answer on May 27, 2026 at 12:39 am

    First of all that’s what system_settings_form_submit does when you press the Reset to defaults button. It calls variable_del which will delete all your defined variables in the form from the variables table.

    Now your form’s #default value is probably filled because you do something like this:

    global $faculty_detail_template_default;
    $form = array (
      '#default_value' => variable_get('faculty_detail_template', $faculty_detail_template_default),
    );
    

    I don’t see why you insist of adding a default value in the variables table. This entire approach is flawed. Just use variable_get($name, $default) wherever your code depends on faculty_detail_template. That’s precisely what the second parameter of this function is used for: $default The default value to use if this variable has never been set. So for Drupal, the absence of a variable from the variable table means it’s up to the coder how to handle this case (provide a default for example). Default value which is specified using variable_get.

    Second, if you used system_settings_form then you already have a submit function, the one mentioned above (system_settings_form_submit) so your faculty_submit won’t be called unless you add it specifically to the array of submit callbacks to be executed. Something like this:

    $form['#submit'][] = 'faculty_submit';
    return system_settings_form($form); 
    

    BTW, using global variables is a bad idea (in general) and you should try to avoid using them. That’s what variables are used for 🙂 Pieces of information which can be retrieved in different parts of the code. So instead add a .install file to your module and in that file you define these global variables using variable_set. This is a lot cleaner than just magically popping some global variables in the middle of the code.

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

Sidebar

Related Questions

I am trying to make this map only allow one marker on the page
When trying to compile a c++ file in textmate (this happens when clicking run),
I'm trying to delay the default action of clicking on a link, until the
I am trying to 1) implement the hook menu and variable_set in the block
I was trying to display a link in a page which will point to
I'm trying to access a date variable from a form individually to the other
Here's what I'm trying to do. When the 'Submit' form is clicked on my
I am moving from VB to C#. I am trying to loop through a
I'm trying to increment a variable in JavaScript by clicking on a link, it
I am trying to include this path to the zend framework, but failing: include_path

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.