Two submit buttons on a single page

Is it possible to provide two submit buttons on a single page, one button should update a different table and display the values, the other button is the final submission button that should be clicked after completing the other form fields

Just have a route for each button. But it would make more sense to hide the last button till it’s required.

Thank you.

My requirement is like this,

A secondary table needs to be updated and the data from the secondary table should be displayed on the page after every addition and finally the main table has to be updated and the secondary table should be updated with status as “completed”.
Can two tables updated in a single method inside the controller

Yes they can :slight_smile: If the two tables are related, then you can do something like $this->TableA->TableB->save, otherwise, use the loadModel() method:


As for having two submit buttons, the best way would be to give them a name with a unique value:


$this->Form->submit('One', ['name' => 'submit']);
$this->Form->submit('Two', ['name' => 'submit']);


if ($this->request->is('post') && $this->request->getData('submit') === 'One') {
//Stuff for one
} elseif ($this->request->is('post') && $this->request->getData('submit') === 'Two') {
//Stuff for two

Disclaimer This might not actually work as I typed it out based on memory and have not tested it.

Thank you, that was helpful. data of team are to be added in a form and displayed in the same page. is there any easy way to add multiple user in a page and display the same.

I presently display the data in a main page that contains the form. the form is posted to another method that redirects to this main page on success. However I need to isolate the data based on Session. Could you please help