Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

* PROPER * reciept of select_multiple data sent with method='post'

The php manual suggest naming the select someting like  name='theselect[]'  so the data will arrive in $_POST array as an array of the options selected.

It works, but it is not satisfying solution.
   name="letters[]" is not proper html as pr definition of cdata http://www.w3.org/TR/html4/types.html#type-cdata
   such names give trouble when you try to use them for javascript adressing of the form element.

browsers permit it and there are workarounds for the javascript adressing; but dammit, the must be some way to do it right.

with method='get' i have found the $_SERVER['QUERY_STRING'] but the amount is limited and anyway method='get' masticate the data, losing linefeeds et al.

I am beginning to suspect a conspiracy here :(

so before i go completly bonkers, would somebody please tell me hov i can get data from a mutiple select with a valid html name  say  
  <select name='nothopeless' multiple>

regards JakobA

0
JakobA
Asked:
JakobA
1 Solution
 
lozlozCommented:
hi,

hmm well i would say you should really be using the name as php suggests. whenever i've had to use javascript in conjunction with php array style names, i've just used a different way of accessing the elements as suggested by php (http://uk.php.net/manual/en/faq.html.php#faq.html.arrays). it works fine using variable = documents.forms[0].elements['theselect[]']; for example.. i can't think of how you would get the data out through POST or GET any other way

loz
0
 
DoppyNLCommented:
if you don't want to use [] in your html you can number the fields manually:

name="field1"
name="field2"
name="field3"
name="field4"
name="field5"

you then have to adjust your loop to walk through these; it's harder to process the form this way, but it is still possible.
0
 
shmertCommented:
Use a regular POST form.  Put this in your php.ini file:

always_populate_raw_post_data = 1

Then you can access the raw post data from the request, and parse out the variables manually, using a function which appends the multiple vars to the $_POST array, and then merges the new $_POST into $_REQUEST.  This would be the most seamless way of doing it, I think.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
shmertCommented:
Something like this should work for you:

<?php
function multipleRequestArguments() {
        $data = $GLOBALS['HTTP_RAW_POST_DATA'] . '&' . $_SERVER['QUERY_STRING'];
        echo $data . "<br />\n";
        $pairs = explode('&', $data);
        $out = array();
        foreach($pairs AS $pair) {
                if (!$pair) continue;
                list($key,$value) = explode('=', $pair);
                if (isset($out[$key])) {
                        if (!is_array($out[$key])) {
                                $out[$key] = array($out[$key], $value);
                        } else {
                                $out[$key][] = $value;
                        }
                } else {
                        $out[$key] = $value;
                }
        }
        return $out;
}
$MULTI_POST = multipleRequestArguments();
print_r($MULTI_POST);
?>
0
 
JakobAAuthor Commented:
>> schmert

Beautifull.  thank you

regards JakobA
0
 
shmertCommented:
Thanks!  One important thing I forgot is calling urldecode() on all the $key and $value items.
0
 
JakobAAuthor Commented:
Right.  And if it that raw, i guess i better subtitite '_' for '.' in the type='image' parameter names.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now