Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP 2.0 Determine which submit button has been clicked
    primarykey
    data
    text
    <p>In CakePHP 1.3 you can create a form with multiple submit buttons:</p> <pre><code>echo $this-&gt;Form-&gt;submit('Submit 1', array('name'=&gt;'submit'); echo $this-&gt;Form-&gt;submit('Submit 2', array('name'=&gt;'submit'); </code></pre> <p>and detect which submit button was pressed in the controller with:</p> <pre><code>if (isset($this-&gt;params['form']['submit']) &amp;&amp; $this-&gt;params['form']['submit'] == "Submit 1") { // first button clicked } </code></pre> <p>In CakePHP, $this->params['form'] isn't set and the clicked button value <strong>doesn't appear anywhere in $this->request, $this->request->data, $this->params, $this->data or $_POST</strong>.</p> <p>How do I determine which button has been clicked in CakePHP 2.0?</p> <p>Thanks in advance.</p> <p>Edit:</p> <p>As requested, here's the code for the form:</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;create('History', array('action'=&gt;'add')); ?&gt; &lt;div class='submit'&gt; &lt;?php echo $this-&gt;Form-&gt;submit('Yes', array('div'=&gt;false, 'name'=&gt;'submit')); echo $this-&gt;Form-&gt;submit('No', array('div'=&gt;false, 'name'=&gt;'submit')); ?&gt; &lt;/div&gt; &lt;?php echo $this-&gt;Form-&gt;end()?&gt; </code></pre> <p>And the output of the form:</p> <pre><code>&lt;form action="/projects/kings_recruit/trunk/www/histories/add" id="HistoryAddForm" method="post" accept-charset="utf-8"&gt; &lt;div style="display:none;"&gt; &lt;input name="_method" value="POST" type="hidden"&gt; &lt;/div&gt; &lt;div class="submit"&gt; &lt;input name="submit" value="Yes" type="submit"&gt; &lt;input name="submit" value="No" type="submit"&gt; &lt;/div&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload