Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've created a simple form and exported it in Drupal API mode. I copied the exported code into a custom module on another site to test.
I want to add a custom submit function for the form, however simply copying the function name and adding '_submit' to the end doesn't seem to work. The only way I could get my custom submit function to work was to add $form['#submit'][] = 'my_form_submit';
to the end of the exported form function.
Why doesn't my submit function run automatically?
Comments
Comment #1
Deciphered CreditAttribution: Deciphered commentedIts highly likely that the issue is that by default the forms use system_settings_form(), as the module is intended for creating variable based configuration forms, if you want to handle the submissions yourself you should be able to just change
return system_settings_form($form);
toreturn $form;
.I do however have plans to have the option to define your own form handling directly while building the form, I just haven't had the time to think the idea through fully.
Let me know how you go.
Comment #2
BWPanda CreditAttribution: BWPanda commentedYes, I'd say that's what the issue is.
To make it easier for myself I'll leave the
return system_settings_form($form);
in place (since that adds the submit button, etc.). Simply adding$form['#submit'][] = 'my_form_submit';
seems to do the trick regarding allowing me to use a custom submit function, so I'll stick with that also.Customising the form handling in the UI sounds like a good idea though, so look forward to seeing what you do there. I'll let you close or change the status of this issue as appropriate.
Comment #3
Deciphered CreditAttribution: Deciphered commentedGlad I could help.
Marking as fixed. Could I possibly ask you to open a feature request for the other part (on train, typing with tablet, access limited)?
Comment #4
BWPanda CreditAttribution: BWPanda commentedNo worries, here you go: #1729976: Custom form handling options in UI