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

Deciphered’s picture

Its 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); to return $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.

BWPanda’s picture

Yes, 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.

Deciphered’s picture

Status: Active » Fixed

Glad 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)?

BWPanda’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.