Skip to content

Commit 91bb857

Browse files
committed
Submit a Form with Multiple Buttons
1 parent 7ff7772 commit 91bb857

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Turbo/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,30 @@ _also_ changes the redirect status code from 302 (the default) to 303
155155
(`HTTP_SEE_OTHER`). That's not required for Turbo Drive, but 303 is "more correct"
156156
for this situation.
157157

158+
> **NOTE:**
159+
> When your form contains more than one submit button and, you want to check which of the buttons was clicked
160+
> to adapt the program flow in your controller. You need to add a value to each button because
161+
> Turbo Drive doesn't send element with empty value:
162+
163+
```php
164+
$form = $this->createFormBuilder($task)
165+
->add('task', TextType::class)
166+
->add('dueDate', DateType::class)
167+
->add('save', SubmitType::class, [
168+
'label' => 'Create Task',
169+
'attr' => [
170+
'value' => 'create-task'
171+
]
172+
])
173+
->add('saveAndAdd', SubmitType::class, [
174+
'label' => 'Save and Add',
175+
'attr' => [
176+
'value' => 'save-and-add'
177+
]
178+
])
179+
->getForm();
180+
```
181+
158182
#### More Turbo Drive Info
159183

160184
[Read the Turbo Drive documentation](https://turbo.hotwire.dev/handbook/drive) to learn about the advanced features offered

0 commit comments

Comments
 (0)