I'm loading a webform on a Ajax modal dialog. The form submission is also set to Ajax. I want to alter the Ajax submit callback so I can have more control over the form behaviour. I'm not being able to do that. The callback being executed is always submitAjaxForm, set on the WebformAjaxFormTrait trait.
1 Answer
Try using a
hook_form_alter(&$form, FormStateInterface $form_state, $form_id) {
....
if (isset($form['actions']['submit'])) {
$form['actions']['submit']['#ajax'] = [
'callback' => '/path/to/your/controller/or/webformhandler/submitModalFormAjax',
'event' => 'click',
];
}
in your *.module and then implement the callback function somewhere
public static function submitModalFormAjax(array &$form, FormStateInterface $form_state) {...}
-
2I've found out hook_webform_submission_form_alter will work as well. Commented Jul 5, 2018 at 14:57