3
function bi_mx_enhancement_form($form, &$form_state) {
    $form['bi_mx_enhancement_government_ws'] = [
        '#type' => 'fieldset',
        '#title' => t('Government Web Service Settings'),
        '#tree' => true,
        '#collapsible' => true,
    ];
    $form['bi_mx_enhancement_government_ws']['base_url'] = [
        '#type' => 'textfield',
        '#title' => t('Base URL'),
        '#default_value' => variable_get('base_url', 'https://'),
        '#description' => t('The base URL of the Government Web Service for Medic Validation. NOTE: Do not add a trailing slash.'),
        '#required' => true,
    ];

    return system_settings_form($form);
}

Variable base_url does not get saved, I always get the default value in the form.

I took a look at Drush, and it is like this:

bi_mx_enhancement_government_ws:
  base_url: 'http://52.203.204.11:8282/api/medicos'
2

Since you are setting #tree to TRUE, the values will be saved in the bi_mx_enhancement_government_ws persistent variable, which will contain an array. For the code you are showing, its value will be similar to the following one.

array(
  'base_url' => 'https://'
);

Instead of variable_get('base_url', 'https://'), consider using the following code.

$values = variable_get('bi_mx_enhancement_government_ws', array());
$ws_base_url = $values['base_url'];

When you are now using variable_get('base_url', 'https://'), you should use $ws_base_url.

Since you seem to just use a single setting for that fieldset, I would rather use '#tree' => FALSE, if that form doesn't have any other form field which is using base_url as identifier.

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.