Jump to content

Recommended Posts

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/130003-php-not-receiving-_request-value/
Share on other sites

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.

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

 

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.