Why does the name or value of the backButton HTML button not appear in $_POST?
-
22-09-2019 - |
Question
Trying to detect when a user clicks "Cancel" but the $_POST on using var_export($_POST) outputs:-
array (
'descr' => '',
'formSubmitted' => '1',
'backButton_x' => '36',
'backButton_y' => '15',
)
Notice: Undefined index: backButton in /home/mholt/development/BusinessPortico/class/requestHandler.class.php on line 81
Here is the HTML:-
<form method="post" class="cssform_dialog" enctype="multipart/form-data">
<div id="dialogContent"></div>
<div id="dialogFooter">
<div class="wrapperLeft"><input type="image" name="nextButton" id="nextButton" value="Yes" src="../new_assets/images/button-save.jpg"/></div>
<div class="wrapperRight"><input value="Cancel" name="backButton" type="image" src="../new_assets/images/button-cancel.jpg"/></div>
<input type="hidden" name="formSubmitted" value="1"/>
</div>
</form>
Solution
Because it is type='image'
— a server side image map.
A strict reading of the specification suggests that browsers should include the value for it, but not all do, so some just send the co-ordinates.
You can look for name.x (or name_x in PHP), or not use an image input in a way it wasn't designed for.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow