Recent Posts
- (09/10) Fixing Warning: the ECDSA host key for 'github.com' differs from the key for the IP addressTAGS:Web Server Admin
- (12/26) CakePHP 3 - Getting List of Column Definitions from a Table (like schema())TAGS:CakephpCake3
- (09/14) Change Order of Loaded Behaviors in CakePHP 3TAGS:Cake3CakephpWeb ProgrammingPhp
- (05/29) CakePHP 3 - Accept JSON Header Only Working When Debug FalseTAGS:Web ProgrammingCakephpCake3
- (05/23) Remove All Events from Google Calendar (Reset Calendar)TAGS:Web ProgrammingPhp
- (11/08) Google Tag Manager (GTM) Not Firing Default PageView EventTAGS:Web ProgrammingJavascriptGoogle Tag Manager
- (10/13) In PHP, how do you get __toString() Magic Method Result without calling echo?TAGS:CakephpCake3Cakephp 13PhpWeb Programming
- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
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 26,176 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
Comments for this Posting
Sorry, comments are closed for this posting.
Please Email Kevin if you have any questions. Thanks!
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