?
Solved

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

Posted on 2003-11-13
7
Medium Priority
?
385 Views
Last Modified: 2010-05-19
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
Comment
Question by:JakobA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9744969
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
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9745788
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
 
LVL 11

Accepted Solution

by:
shmert earned 1000 total points
ID: 9749167
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
Independent Software Vendors: 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!

 
LVL 11

Expert Comment

by:shmert
ID: 9749328
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
 
LVL 15

Author Comment

by:JakobA
ID: 9749578
>> schmert

Beautifull.  thank you

regards JakobA
0
 
LVL 11

Expert Comment

by:shmert
ID: 9749723
Thanks!  One important thing I forgot is calling urldecode() on all the $key and $value items.
0
 
LVL 15

Author Comment

by:JakobA
ID: 9749808
Right.  And if it that raw, i guess i better subtitite '_' for '.' in the type='image' parameter names.
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question