Recent Posts
- (02/24) Calling an Element from a Helper TAGS:CakephpWeb ProgrammingUsageTutorialExample
- (10/14) Forcing A Single Join in CakePHP PaginationTAGS:CakephpCakephp 13DatabaseErrorsHabtmMysqlMssqlWeb ProgrammingUsage
- (08/11) Inserting NOW() into MySQL Using CakePHPTAGS:CakephpDatabaseMysqlMssqlWeb ProgrammingUsage
- (08/07) Best PaginateCount for CakePHP - with Group By SupportTAGS:CakephpBehaviorsWeb ProgrammingUsageDatabaseExampleMysqlHabtmHack
- (04/03) CakePHP Error Messages Not Showing on FormTAGS:CakephpCakephp 13Web ProgrammingErrorsUsage
- (02/06) Sorting Paginated Results Using a Related Model Field in CakePHPTAGS:CakephpWeb ProgrammingUsageExample
- (11/02) Changing CakePHP's Model useTable on the FlyTAGS:CakephpWeb ProgrammingMysqlDatabaseExampleTutorial
- (10/18) The Funniest Error Message Ever - Thank You EclipseTAGS:EclipseWeb ProgrammingErrorsHumorWindowsUsageSoftwarePhpCakephp
Subscribe to my feed
MainelyDesign.com Blog
Which Submit Button was Clicked in CakePHP? Use Name.
Posted on 03/04/2010 at 12:01 pm by Kevin Wentworth
Viewed 6,559 times | 2 comments
If you want to have multiple submit buttons that make a form do different things there's a simple way to do this. The name of the submit button that was clicked by the user will be sent (via POST) with all the other POSTed data. This is very handy if you want to have a cancel button and continue button. In CakePHP the name of the button won't be in $this->data, but it's easy enough to get...
Give the Submit Button a Name
If you don't provide a name for your submit button, when the user clicks the button, the form will simply submit. If you assign a name (and make sure it's unique) then you can determine which button was clicked by the user.
Find Out Which Button was Clicked
- //user clicked the submit button named proceedToCheckout... so we'll do that
- }
Figuring out which button was clicked by the user is easy...just look in $this->params['form']['buttonName'] where buttonName is what you named your button. I just check to make sure it's isset() because the value doesn't matter.
Cheers,
-Kevin Wentworth
Tags for Which Submit Button was Clicked in CakePHP? Use Name.
Cakephp | Web Programming | Usage | Example | Forms | Tutorial

Posted by André Vieira
on 20/6/10
That method works well when I'm using simple $form-submit(), but when I try to do it using $ajax->submit(), or $ajax->form() (... ) $form->submit, my $this->params['form'] is always empty.
I'm already saying ajax to use POST.
Thank you