When working with the multidimensional forms, I found I wanted to perform some actions to some elements in the form. For example, deleting a sub element using a button. I found the nice <button> tag which allows you to have a separate submit value from the label of the button. I later found that it doesn't work right in Internet Explorer. Poking around for a solution, most were solved using JavaScript. But I didn't want to bring JavaScript into the game because people may not have it enabled and the level of complexity goes up. So, I sort of came up with my own solution to fix it entirely with PHP.
Instead of using <button> I went back to the input method, but to be able to get the value and the label to be different, I had to do something a little different. I ended up putting the name and the value into the name attribute. For example:
<input type="submit" name="btnDeleteRow=<?php echo $rowNumber; ?>" value="Delete" />
In order to be able to work with with it, I created a function to take care of parsing out the key value pairs and throwing it back in to the $_POST array:
function fixIEButtons($arr) { foreach($arr as $key => $value) { if(substr($key, 0, 3) == "btn" && strrpos($key, "=")) { // this is a button that needs to be evaluated $button = explode("=", $key); $arr[$button[0]] = $button[1]; } } return $arr; }
Attached is a text file with PHP code that demonstrates what IE does in the different ways of doing things.
Attachment | Size |
---|---|
ieButtons.txt | 1.33 KB |