| 5 system.module | system_settings_form($form) |
| 6 system.module | system_settings_form($form) |
| 7 system.module | system_settings_form($form) |
| 8 system.module | system_settings_form($form) |
Add default buttons to a form and set its prefix.
Parameters
$form: An associative array containing the structure of the form.
Return value
The form structure.
See also
Related topics
File
- modules/
system/ system.module, line 1103 - Configuration system that lets administrators modify the workings of the site.
Code
<?php
function system_settings_form($form) {
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['buttons']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
);
if (!empty($_POST) && form_get_errors()) {
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
}
$form['#submit'][] = 'system_settings_form_submit';
$form['#theme'] = 'system_settings_form';
return $form;
}
?> Login or register to post comments
Comments
One little bug with this
One little bug with this function is that if you have your whole form in fieldset the buttons wont be in it.
Your whole form should really
Your whole form should really not be in a fieldset!
Sometimes there are good
Sometimes there are good reasons to put the whole form in a fieldset, e.g., when placing a settings form (collapsed or not) at the top of a page that contains other content.
The method to move buttons into the fieldset is fairly simple – just don't return system_settings_form() immediately but manipulate it a bit:
// ...definition of the form as usual...$form = system_settings_form($form);
$form['fieldset']['buttons'] = $form['buttons'];
unset ($form['buttons']);
return $form;
Replace 'fieldset' with the name of your fieldset, of course.
Yeah. - and sometimes you just want to remove the Reset button
To just remove the reset button, do like this:
unset ($form['buttons']['reset']);
fieldset issue SOLVED
ivanjaros,
I had the same problem as you and spent too much time trying to figure this out, but I finally did. According to the Form API QuickStart guide:
An important thing to note: notice that $form['access'] has a '#tree' => TRUE attribute. this setting retains the full tree structure for all elements under it when it is passed to $form_state['values']. you must explicitly declare this anywhere you wish to retain an array's full hierarchy when it is passed.
My fieldset had #tree set to TRUE. When I removed that, the field values were flattened and placed in the 'values' array of form_state and then system_settings_form_submit was able to find them and process them.