Req #42960 [Opn]: PHP messes up image submit button data
| From: | cmb@php.net | Date: | Wed, 22 Sep 2021 13:41:00 +0000 |
| Subject: | Req #42960 [Opn]: PHP messes up image submit button data | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236751@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=42960&edit=1
ID: 42960
Updated by: cmb@php.net
Reported by: efbiaiinzinz at hotmail dot com
Summary: PHP messes up image submit button data
Status: Open
Type: Feature/Change Request
Package: *General Issues
Operating System: *
PHP Version: 5.2.4
Block user comment: N
Private report: N
New Comment:
Regarding HTTP, there is nothing special with parameter names
containing brackets or dots. Regarding HTML forms, for <input
type="image" name="foo"> actually two parameters are sent (foo.x
foo.y). PHP translates any dots in HTTP parameters to
underscores, and treats bracketed parts as array indexes.
However, it just ignores *any* trailing content after the last
bracket pair.
> Using the extra [] seems to be ok as workaround?
I wouldn't rely on that. Maybe better don't use arrays for
multiple images, but roll your own treatment. E.g. use names like
smth_1, smth_2, etc., and scan for these array indexes (smth_1_x,
etc.)
Previous Comments:
------------------------------------------------------------------------
[2021-09-13 14:34:33] ddpm at liscovius dot de
What the "living" standard says:
https://html.spec.whatwg.org/multipage/input.html#image-button-state-(type=image)
------------------------------------------------------------------------
[2021-09-13 14:06:16] ddpm at liscovius dot de
My previous comment shows a better example to understand the issue.
Using the extra [] seems to be ok as workaround?
------------------------------------------------------------------------
[2021-09-13 14:04:24] ddpm at liscovius dot de
<div style="display:flex;gap:1em;">
<div>With GET using name[key]:
<form action="" method="GET">
<input type="image" name="smth[imgsubmitget]" alt="imgclick coords using
get" src="t.jpg" width="200" height="200"></form>
</div>
<div>With GET using name[key][]:
<form action="" method="GET">
<input type="image" name="smth[imgsubmitpost][]" alt="imgclick coords
using get (ok)" src="t.jpg" width="200"
height="200"></form>
</div>
<div>With POST using name[key]:
<form action="<?= basename(__FILE__) ?>" method="POST">
<input type="image" name="smth[imgsubmitpost]" alt="imgclick coords
using post" src="t.jpg" width="200" height="200"></form>
</div>
<div>With POST using name[key][]:
<form action="<?= basename(__FILE__) ?>" method="POST">
<input type="image" name="smth[imgsubmitpost][]" alt="imgclick coords
using post (ok)" src="t.jpg" width="200"
height="200"></form>
</div>
</div>
<pre>
$_POST: <?php print_r($_POST); ?>
$_GET: <?php print_r($_GET);?>
$_REQUEST: <?php print_r($_REQUEST);?>
</pre>
name[key]: browser sends get data:
testinputimage.php?smth[imgsubmitget].x=175&smth[imgsubmitget].y=177
name[key][]:browser sends get data:
testinputimage.php?smth[imgsubmitpost][].x=65&smth[imgsubmitpost][].y=114
Browser send postdata: smth%5Bimgsubmitpost%5D.x=93&smth%5Bimgsubmitpost%5D.y=88
------------------------------------------------------------------------
[2007-10-15 09:53:07] jani@php.net
Reopened. This is valid issue. Just not a bug but feature/change request.
------------------------------------------------------------------------
[2007-10-14 12:13:56] bjori@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
See bug#42162
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=42960
--
Edit this bug report at https://bugs.php.net/bug.php?id=42960&edit=1