HeidiR Posted October 24, 2008 Share Posted October 24, 2008 Hello all, I have a simple test form below with two submit buttons. One standard text and the other is an image. When, submitting via the standard text button, the value "testval" (from $_REQUEST['cmd']) is displayed (echoed) as expected. However, when submitting via the image button, the value of $_REQUEST['cmd'] is blank and noting is displayed. What am I missing? Thanks, HeidiR <?php echo("CMD:" . $_REQUEST['cmd']); $str = "<br /><form method=post action=" . $PHP_SELF . ">"; $str .= "<table>"; $str .= "<tr><input name=cmd type=image value='testval' src='../images/email2.gif'></td></tr>"; $str .= "<tr><input name=cmd type=submit value='testval'></td></tr>"; $str .= "</table>"; $str .= "</form>"; echo ($str); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130003-php-not-receiving-_request-value/ Share on other sites More sharing options...
discomatt Posted October 24, 2008 Share Posted October 24, 2008 print_r( $_REQUEST['cmd'] ); Images return an array of the x,y coordinates that were clicked. Quote Link to comment https://forums.phpfreaks.com/topic/130003-php-not-receiving-_request-value/#findComment-673996 Share on other sites More sharing options...
Maq Posted October 24, 2008 Share Posted October 24, 2008 Try changing: echo("CMD:" . $_POST['cmd']); $str = " </pre> <form method="post" action=".%20%24_SERVER%5B'PHP_SELF'%5D%20.%20">"; < You should probably keep the names of your submit button and your image different, I'm not sure if it will make a difference. Quote Link to comment https://forums.phpfreaks.com/topic/130003-php-not-receiving-_request-value/#findComment-673999 Share on other sites More sharing options...
HeidiR Posted October 25, 2008 Author Share Posted October 25, 2008 Thanks for your quick reply guys. I tried $_SERVER['PHP_SELF'] and $_POST['cmd']); without success. However, after additional research and testing, I learned that this is an issue with IE not sending the value attribute with an image submit button. The solution I implemented is: if($cmd == '' AND is_numeric($_REQUEST['cmd_x'])) $cmd = "testval"; Thanks again for all your help. HeidiR Quote Link to comment https://forums.phpfreaks.com/topic/130003-php-not-receiving-_request-value/#findComment-674272 Share on other sites More sharing options...
PFMaBiSmAd Posted October 25, 2008 Share Posted October 25, 2008 You will find that the 'cmd_x' and 'cmd_y' will be sent by all browsers and only some will send 'cmd'. The w3.org specification only states that the 'cmd_x' and 'cmd_y' values for an image must be sent. It does not even suggest that browsers send the 'cmd' value. Don't get in the habit of using $_REQUEST. If your code is expecting POST data, you should use $_POST, if your code is expecting GET data, you should use $_GET, and if your code is expecting COOKIE data, use $_COOKIE. $_REQUEST should be avoided because it combines those three different sources. This eliminates one level of validation about where the data actually is coming from and you won't believe the number of people posting in a forum like this asking why they are not receiving the correct data, when they have ended up with post/get/cookie variables by the same name and they overwrite each other in the $_REQUEST variable. Quote Link to comment https://forums.phpfreaks.com/topic/130003-php-not-receiving-_request-value/#findComment-674331 Share on other sites More sharing options...
HeidiR Posted October 26, 2008 Author Share Posted October 26, 2008 You will find that the 'cmd_x' and 'cmd_y' will be sent by all browsers and only some will send 'cmd'. The w3.org specification only states that the 'cmd_x' and 'cmd_y' values for an image must be sent. It does not even suggest that browsers send the 'cmd' value. Don't get in the habit of using $_REQUEST. If your code is expecting POST data, you should use $_POST, if your code is expecting GET data, you should use $_GET, and if your code is expecting COOKIE data, use $_COOKIE. $_REQUEST should be avoided because it combines those three different sources. This eliminates one level of validation about where the data actually is coming from and you won't believe the number of people posting in a forum like this asking why they are not receiving the correct data, when they have ended up with post/get/cookie variables by the same name and they overwrite each other in the $_REQUEST variable. Thanks for the additional information and suggestion for not using $_REQUEST. I tested the original code on Firefox and it worked perfectly by sending the value attribute with the image submit button as well as the standard button. This confirms this is an IE shortcoming! HeidiR Quote Link to comment https://forums.phpfreaks.com/topic/130003-php-not-receiving-_request-value/#findComment-674925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.