# Two submit buttons on a single page

**URL:** <https://discourse.cakephp.org/t/two-submit-buttons-on-a-single-page/2384>\
**Category:** Uncategorized\
**Created:** [April 9, 2017, 5:57pm UTC](https://discourse.cakephp.org/t/two-submit-buttons-on-a-single-page/2384 "2017-04-09T17:57:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![beracah.kings](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@beracah.kings](https://discourse.cakephp.org/u/beracah.kings)\
**Post date:** [April 9, 2017, 5:57pm UTC](https://discourse.cakephp.org/t/two-submit-buttons-on-a-single-page/2384/1 "2017-04-09T17:57:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [April 10, 2017, 2:06am UTC](https://discourse.cakephp.org/t/two-submit-buttons-on-a-single-page/2384/2 "2017-04-10T02:06:50Z")

</div>

> [@beracah.kings](#):
>
> the other button

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

---

<div class="post-metadata">

**Author:** ![beracah.kings](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@beracah.kings](https://discourse.cakephp.org/u/beracah.kings)\
**Post date:** [April 10, 2017, 5:32pm UTC](https://discourse.cakephp.org/t/two-submit-buttons-on-a-single-page/2384/3 "2017-04-10T17:32:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [April 11, 2017, 12:25pm UTC](https://discourse.cakephp.org/t/two-submit-buttons-on-a-single-page/2384/4 "2017-04-11T12:25:07Z")

</div>

> [@beracah.kings](#):
>
> Can two tables updated in a single method inside the controller

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

```auto
$this->loadModel('TableB');
$this->TableB->save()

```

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

Template.ctp

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

```

Controller

```auto
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.

---

<div class="post-metadata">

**Author:** ![beracah.kings](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@beracah.kings](https://discourse.cakephp.org/u/beracah.kings)\
**Post date:** [April 11, 2017, 12:40pm UTC](https://discourse.cakephp.org/t/two-submit-buttons-on-a-single-page/2384/5 "2017-04-11T12:40:42Z")

</div>

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
