How to break Drupal's system_settings_form submit handling without trying
UPDATE for Drupal 6: If you provide a submit handler for a drupal_set_form form, you no longer have to add the system handler explicitly too.
The array() silliness at the end is gone, instead #submit itself is a simple, non-associative array.
In Drupal 6, whether the form is handled by the settings page helpful form wrapper or not, all you have to do is tack on another function to call.
<?php
/**
* Implements hook_form_FORM_ID_alter() for salesforcewebform_admin_settings.
*/
function visitorpath_form_salesforcewebform_admin_settings_alter($form, &$form_state) {
$form['#submit'][] = 'visitorpath_salesforcewebform_admin_settings_submit';
}
?>
From Ben Shell's comment below, here's how to do this in Drupal 5.
If you provide a submit handler for a drupal_set_form form, you must add the system handler explicitly too.
<?php
$form['#submit']['my_custom_settings_submit_helper'] = array();
$form['#submit']['system_settings_form_submit'] = array();
?>
Please note that this post was originally written in 2007 (and Shell's comment, which shows the awesomeness of the open source community, came a year later... which is also awesome in a way). Really, I've known how to do this right for quite a while. And even documented it, somewhere. But somehow I keep finding myself back on this old embarrassing post :-P
All of the below is moot.
AAAAAAUUUUUggggGGGGGHHHHHHhhhRRrrrr
So class, the lesson today is that if you have system_settings_form($form) form (meaning masic submit and creating variables is handled automatically), you CANNOT have a helper submit function with the same name plus _submit.
OK, you already knew that.
Additionally -- and here's where the screams come in -- you cannot have it with a similar name where the whole thing is prefixed with an underscore, either.
Oh, never mind. Agaric had both functions beginning with an underscore:
function _userreference_access_admin()
function _userreference_access_admin_submit($form_id, &$form_values)
Don't let this happen to you! Tell your children!
$form['#submit']['_userreference_access_admin_submit_helper'] = array();
function _userreference_access_admin_submit_helper($form_id, &$form_values)
That's better. Um, no, it's not.
OK. Apparently Drupal 5 has no way to use the drupal core system settings submit function and an additional custom one as a supplement, and I was delusional just to try, let alone to think it worked for a moment.
You can still name your own submit function, but understand it will override and you have to save all your values yourself, counting on
No free variable saving if you want to do anything else.
Now you know.
If you want to take over part of submit handling for a system_settings_form handled form, you have to take over all the submit handling.
Or can you have element-level submit handlers? I guess so. But whatever. Using set_variable ain't that hard.
[Hope you read the top of this post, because all the stuff you just read is wrong!]
Comments
Solution
I found the answer to this problem at http://drupal.org/node/58689
You just have to manually add the default submit handler to the #submit array:
$form['#submit']['my_custom_settings_submit_helper'] = array();
$form['#submit']['system_settings_form_submit'] = array();
Nice!
Thanks!
Post new comment