Home » HTTP » HTTP_Request » Bug #7846
posted form data elements with the same name are overwritten by the latest
Details
| Request #7846 | posted form data elements with the same name are overwritten by the latest |
|---|---|
| Submitted | 2006-06-09 09:24 UTC |
| From | to dot bogdan at gmail dot com |
| Status | Bogus |
| Package | HTTP_Request |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2006-06-09 09:24 UTC] to dot bogdan at gmail dot com
Description:
------------
I'm using HTTP_Request through HTTP_Client,
and noticed that posting forms does not allow posting
different values with the same name ( in addPostData() in Request.php ).
At the same time, browsers do send
form fields with identical names as separate rows of the POST request.
Not sending duplicate names automatically disallows the use of any servers, accepting parameters as multiple lines with the same names.
Single example: http://www.ensembl.org/Multi/martview; extract of posted form:
-----------------------------146043902153
Content-Disposition: form-data; name="collection_xrefs"
entrezgene
-----------------------------146043902153
Content-Disposition: form-data; name="collection_xrefs"
unigene
RFC2388 on multipart/form-data: '3. In forms, there are a series of fields to be supplied by the user who fills out the form. Each field has a name. Within a given form, the names are unique. ... 5.5... The relationship of the ... ordering of returned values within "multipart/form-data" is not defined by this specification, nor is the handling of the case where a form has multiple fields with the same name.'
I do not know how to handle/solve this problem.
Test script:
---------------
using HTTP_Client:
$data = array(
'collection_chromosome_attributes'=>'chromosome_name',
'collection_chromosome_attributes'=>'start_position');
$code = $req->post($url, $data);
this generates the following calls in HTTP_Client::post():
foreach ($data as $name => $value) {
$request->addPostData($name, $value, $preEncoded);
and in addPostData() the latest form-data value replaces any previous with the same name.
Expected result:
----------------
posted to server:
collection_chromosome_attributes=chromosome_name
collection_chromosome_attributes=start_position
Actual result:
--------------
posted to server:
collection_chromosome_attributes=start_position
[2006-06-09 11:45 UTC] to dot bogdan at gmail dot com
For my specific case, I found a simple script-level solution:
after preparing 'data' array (to be posted), I convert it into 'name=value' pairs, joined by \r\n, and specify 'preencoded=true'. This way data is sent unchanged, allowing multiple non-unique names with different values to reach the server.
[2006-06-09 12:02 UTC] to dot bogdan at gmail dot com
note to my previous comment: one should not prepare any associative array, if there are identical names, for the obvious reasons... sorry for misleading.
[2006-06-09 12:12 UTC] to dot bogdan at gmail dot com
i think it would still be good to allow sending multiple same-named fields from within HTTP_Request...