Re: Strange variable received

From: Date: Thu, 15 May 2003 17:40:44 +0000
Subject: Re: Strange variable received
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147745@lists.php.net to get a copy of this message
At 17:47 15.05.2003, César Aracena said: --------------------[snip]-------------------- >I'm trying to send some variables from a form to another page (first time >since formatting) and I can't get them. When I pointed the form to >phpinfo.php, I get every variable well, except for the button's name which >I need for an IF statement. It's an image called "change?default" and the >variables I receive are: > >_POST[change_default_x] 33 >_POST[change_default_y] 17 > >so these are the width and height of my button's image, but I want to get >the button's name as a variable... why is this? --------------------[snip]-------------------- This is the standard behaviour for image type buttons. Since <input type="image"> elements can be used as server-side map the specification dictates that the browser sends the exact coordinates of the image where the user clicked on. You will never get the image button name alone. If the form was submitted via mouse click you will most certainly find positive values in both the *_x and *_y parameters (mouse coordinates relative to the image). If the form has been submitted by keyboard/enter (tab the focus onto the image, and press Enter), both values will contain zero (0). So make sure you test for existence, not for true/false of the parameters, or you'll miss a keyboard submission. Example: // this will miss a keyboard submission if ($_POST['<name>_x']) { .... // this will correctly identify a keyboard submission if (array_key_exists('<name>_x', $_POST)) { .... If you code in a way that's separating logic from presentation, your form handler code may not know if the button named <name> will be implemented as <input type="submit"> or <input type="image">. In this case you need to test for <name>, and for <name>_x to catch both possibilities: if (array_key_exists('<name>', $_POST) || array_key_exists('<name>_x', $_POST)) { .... HTH, -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#147745) next »