how second submit button to access form's fields?

2 months ago

winman1
Member | 8
+
0
-

guys,

i have such form:

$form->addSubmit(‘secondSubmit’, ‘…’)
->onclick([$this, ‘actionSecondSubmit)’]);

can anyone tell me if the function call on clict event on this second submit button MUST BE an ‘action’?
how this function call can access the form's fields?

Many thanks for your time.

Last edited by winman1 (2019-06-30 20:18)

2 months ago

filsedla
Member | 81
+
0
-

Hello,
the form callback should not be an “action” method. The form submits at the same “action” where it was rendered.

You can use this structure with multiple submit buttons:

protected function createComponentForm()
{
    ...
    $form->addSubmit('save')->onClick[] = [$this, 'formSubmittedBySave'];
    return $form;
}

public function formSubmittedBySave(SubmitButton $submit)
{
    $form = $submit->getForm();
    $values = $form->getValues();
    ...
}

2 months ago

winman1
Member | 8
+
0
-

thank you very much
dear filsedla!!!