how second submit button to access form's fields?

winman1
Member | 10
+
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)

filsedla
Member | 101
+
+1
-

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();
    ...
}
winman1
Member | 10
+
0
-

thank you very much
dear filsedla!!!