2

I would like to create module based on other custom module. One thing that will be nice to able to do is to alter module settings form fields. Is this possible?

2
  • 1
    Yes, it is possible. Most common way is to use hook_form_alter() or hook_form_FORM_ID_alter().
    – kalabro
    Oct 11, 2012 at 16:44
  • 2
    Don't forget to add dependencies in your module to other custom module.
    – svetlio
    Oct 11, 2012 at 16:44

1 Answer 1

3

You can alter any forms using hook_form_alter(). $form, $form_states, and $form_id are the parameters it gets.

Do not forget to add the following line, at the end of your hook_form_alter() or hook_form_FORM_ID_alter().

    $form = system_settings_form($form);

If you don't want to add the "Save configuration" button, you have to add your custom callback submit with $form['#submit'][] = '_my_callback_form_submit'; and use code similar to the following one.

function _my_callback_form_submit($form, &$form_state) {
  variable_set('my_variable_name', $form_state['values']['my_variable_name']);
}
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.