php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42162 The x coordinate disappears from form request
Submitted: 2007-07-31 17:32 UTC Modified: 2007-09-02 20:58 UTC
From: xoneca+php at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.3 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2007-07-31 17:32 UTC] xoneca+php at gmail dot com
Description:
------------
Indexed <input type="image" /> returns only "Y" value  but not "X".

Reproduce code:
---------------
<form method="get">
  <input type="image" src="image.gif" name="image[2]">
</form>

<pre><?php var_dump($_GET); ?></pre>

Expected result:
----------------
array(1) {
  ["image"]=>
  array(2) {
    ["x"]=>
    string(1) "3"
    ["y"]=>
    string(1) "2"
  }
}

// OR:
array(2) {
  ["image_x"]=>
  array(1) {
    [0]=>
    int(3)
  }
  ["image_y"]=>
  array(1) {
    [0]=>
    int(2)
  }
}

// Or something similar.

Actual result:
--------------
array(1) {
  ["image"]=>
  array(1) {
    string(1) "2"
  }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-01 11:29 UTC] xoneca+php at gmail dot com
I said that submiting a form with an image like this (note the 2nd index set in the name attribute):

  <input type="image" src="image.png" name="image[2]" />

PHP will create:

array(1) {
  ["image"]=>
  array(1) {
    [2]=>
    string(2) "45"
  }
}

Where 45 is the Y coordinate, but PHP forgets to store also the X coordinate as expected:

array(1) {
  ["image"]=>
  array(2) {
    [0]=>
    string(2) "45"
    [1]=>
    string(2) "32"
  }
}

But this one (note the index not set in the name attribute):

  <input type="image" src="image.png" name="image[]" />

Will create:

array(1) {
  ["image"]=>
  array(2) {
    [0]=>
    string(2) "59"
    [1]=>
    string(2) "22"
  }
}

Where 59 is the X coordinate and 22 the Y one.
 [2007-08-04 14:28 UTC] jani@php.net
Does it happen with any browser? f.e. Firefox? 
 [2007-08-31 16:50 UTC] xoneca+php at gmail dot com
It happens in both FF2 and IE7.
 [2007-09-02 20:07 UTC] jani@php.net
What SAPI are you using (CGI, Apache, something else) ??
 [2007-09-02 20:07 UTC] jani@php.net
And does this happen with PHP 5.2.4?
 [2007-09-02 20:15 UTC] xoneca+php at gmail dot com
I am using PHP as Apache module, and this also happens with PHP 5.2.4
 [2007-09-02 20:58 UTC] bjori@php.net
<input type="image" name="image[key]" /> gets translated into ?image[key].x=foo&image[key].y=bar

PHP has no idea what to do with "image[key].x" so the ".x" is stripped away and the "image" array created with the index "key".
Then PHP tries to parse "image[key].y"... strips the ".y" away and overwrites the the previous array index named "key".

If you really want the coordinates into an array you can use name="image[key][]" which will create your "expected result" array.
I however do not recommend it...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 04 00:01:27 2025 UTC