Can you send an array with various values in html? I would like to send different array values with various different submit buttons all within one <form>
element.
Here is what I am doing currently. It works so I'm not having a problem, but I couldn't find any documentation for anything similar and I am really curious if theres another way.
Button with my *psuedo*array
<input type="submit" name="form_action" value="action:new_business,id:0">
Decode function:
$action = explode(',', $_POST['form_action']);
$new = array();
foreach ($action as $v) {
$t = explode(':',$v);
$new[$t[0]] = $t[1];
}
print_r($new);
And the results:
Array ( [action] => new_business [id] => 0 )
Of course, this works, so I'm really just curious whether there's a built in solution already.
The desired simplicity:
<input type="submit" name="array" value="array('0'=>'foo','1'=>'bar')">
print_r($_POST['array]);
Array ( [0] => foo [1] => bar )
Edit: I know how to send arrays with html, but that was not my question. If I use hidden inputs, they get sent regardless of which submit button I click, there will be multiple submit buttons contained in one <form>
element, and I need to know which was clicked and what action it is going to be used for. Sorry if that was unclear but I don't think I deserve downvotes either way...