title: Passing multiple pieces of data in one submit button
body: <p>I have a data table that has a list of entities on a website. The list has 'action' buttons like 'edit', 'delete' and 'enable/disable' (it's a toggle button, but that really doesn't matter here). The edit button is actually a link pretending to be a button, so let's discount that, but the delete and enable buttons need to pass back to a script exactly what needs deleting or enabling. And this ideally needs to be under one 'action' parameter. There is one <code>&lt;form&gt;</code> that encompasses the entire table.</p>
  
  <p>In the following code I'm very much paraphrasing my actual code, and I do use a PHP framework and template engine normally. However, for the purposes of these examples I'll use as plain PHP as possible. (This question is not directly related to PHP though, it's very much HTML and forms.)</p>
  
  <p>Here's an example of a row in my data table:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;&lt;?php echo $item-&gt;name; ?&gt;&lt;/td&gt;
      &lt;td&gt;
          &lt;a href="edit.php?id=&lt;?php echo $item-&gt;id; ?&gt;" class="btn btn-default"&gt;Edit&lt;/a&gt;
          &lt;button type="submit" name="delete" value="&lt;?php echo $item-&gt;id; ?&gt;"&gt;&lt;/button&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>So now I need to add an enable button:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;&lt;?php echo $item-&gt;name; ?&gt;&lt;/td&gt;
      &lt;td&gt;
          &lt;a href="edit.php?id=&lt;?php echo $item-&gt;id; ?&gt;"&gt;Edit&lt;/a&gt;
          &lt;button type="submit" name="enable" value="&lt;?php echo $item-&gt;id; ?&gt;"&gt;&lt;/button&gt;
          &lt;button type="submit" name="delete" value="&lt;?php echo $item-&gt;id; ?&gt;"&gt;&lt;/button&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>At this point, my script that handles this is looking like it's going to end up with lots of <code>if (isset($_POST['delete']))</code> type lines, as I'll need a new one for each action, so I think I'll send the action as a parameter in the form too. Now I have two options:</p>
  
  <pre><code>&lt;button type="submit" name="action[enable]" value="&lt;?php echo $item-&gt;id; ?&gt;"&gt;&lt;/button&gt;
  &lt;button type="submit" name="action[delete]" value="&lt;?php echo $item-&gt;id; ?&gt;"&gt;&lt;/button&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;button type="submit" name="action[&lt;?php echo $item-&gt;id; ?&gt;]" value="enable"&gt;&lt;/button&gt;
  &lt;button type="submit" name="action[&lt;?php echo $item-&gt;id; ?&gt;]" value="delete"&gt;&lt;/button&gt;
  </code></pre>
  
  <p>Conditions:</p>
  
  <ul>
  <li>I'd like to <em>not</em> rely on JavaScript to do anything for me, so no 'onclick set two different hidden inputs values' please</li>
  <li>I'd like to use this method where I'm kinda saying <code>action=delete, id=3</code> somehow in one key=>value pair, but of course if there's a better way then do let me know</li>
  </ul>
  
  <p>So, my questions:</p>
  
  <ul>
  <li>What's the best of those two options?</li>
  <li>Would there be any reason to go for one over the other?</li>
  <li>Is there something else I haven't considered?</li>
  </ul>