Solved

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

Posted on 2003-11-13
7
373 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 250 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

732 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