0

I need to add my submit function to the node insert/edit form.

Here's my code.

function yrv_event_trainer_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id)
{
    if (in_array($form_id, ['node_veranstaltung_edit_form', 'node_veranstaltung_form'])){
        // Here we're adding our submit function before standard one.
        array_unshift($form['#submit'], 'yrv_event_trainer_submit');
    }
}

function yrv_event_trainer_submit(&$form, FormStateInterface $form_state){
// Here's code inside my submit function 
}

But when I'm pressing the "Save and publish" button on the form, this submit function doesn't execute.

For example, I can't debug it having set a breakpoint inside the submit function.

But the array $form['#submit'] has my submit function.

Could you clarify me, what can be a reason of the problem ?

1 Answer 1

2

In node forms the submit callbacks from #submit are not executed. Instead, there are executed submit from #submit property of submit form element. You should add the submit in this way:

$form['actions'][$action]['#submit'][] = 'yrv_event_trainer_submit';

Here is an example too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.