- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
- (06/12) View Layer - Getting count of Entities in View in Cakephp 3TAGS:CakephpCake3
- (05/23) Changing URL in beforeRedirect() in Component - Cakephp 3TAGS:CakephpCake3Web Programming
- (01/28) Foundation CSS Framework ResourcesTAGS:FoundationCss
- (01/27) Change View File from Controller in CakePHP 3TAGS:CakephpCake3UsageWeb Programming
- (01/13) Loading Model/Table Anywhere in Cake3TAGS:Cake3Cakephp
- (10/06) CURL PHP 5.5 Issue on Windows (Using Twilio SDK)
Subscribe to my feed
Which Submit Button was Clicked in CakePHP? Use Name.
Posted on 03/04/2010 at 12:01 pm by Kevin Wentworth
Viewed 19,611 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
- echo $form->submit('Checkout Now', array('name'=>'proceedToCheckout'));
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
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.