SS 4.2.1
Hi!
I am trying to add another form action to a form. The form has two buttons on the front end but even if I click on the second form action, the first form action function is called instead of the second one.
Can anyone please help?
Example code below
public function HelloForm()
{
$fields = new FieldList(
TextField::create('Name', 'Your Name')
);
$actions = new FieldList(
FormAction::create('doSayHello')->setTitle('Say hello'),
FormAction::create('doSayBye')->setTitle('Say bye')
);
$required = new RequiredFields('Name');
$form = new Form($this, 'HelloForm', $fields, $actions, $required);
return $form;
}
public function doSayHello($data, Form $form)
{
$form->sessionMessage('Hello ' . $data['Name'], 'success');
return $this->redirectBack();
}
public function doSayBye($data, Form $form)
{
$form->sessionMessage('Bye ' . $data['Name'], 'success');
return $this->redirectBack();
}