In my Controller I'm loading a form with the following code.
$form = \Drupal::formBuilder()->getForm('Drupal\custom_module\Form\CustomForm');
Depending on different cases I would like to use different processing of the form.
I see 3 possibilities to handle this:
- Use different forms and load the correct depending on the case
- Include some hidden fields and evaluate these fields in the submit handler of the form
- Use different submit handlers
I think the third possibility is the best one. But when I try to use a custom submit hanlders.
$form['#submit'] = 'custom_module_form_submit'; // or $form['actions']['submit']['#submit'] = 'custom_module_form_submit';
They both don't work. How can this be achieved? Is there a better way of doing this?