Hi Geoff,

This is actually more of a PHP question than a Prototype one. :-)
Prototype will serialize the multi-select in the standard way, which
results in POST data looking something like this (assuming I've
selected blue and white):

    colour_value=blue&colour_value=white

Note how the field name is repeated for each value. (The same sort of
thing happens if you have multiple text inputs with the same name.)

How you deal with it at the server-side depends on your server-side
technology. In PHP, there's a special feature where you can flag up
for the PHP engine that you're going to be getting multiple values for
the name and that you want to handle them as an array: Put [] after
the field name:

    <select name="colour_value[]" size= "2" multiple="multiple">

PHP will then automatically combine those values into a zero-based
array called "colour_value":

    $colour_value = $HTTP_GET_VARS['colour_value'];
    echo "Count: ".sizeof($colour_value);

So you can then loop through them in the normal way.

Don't know how good it is (I'm not much of a PHP guy, you just
happened to hit one of the three or so things I know about PHP --
picked it up because people would post questions with these weird
field names with brackets in them!), but I found an article discussing
this here:
http://www.opensourcetutorials.com/tutorials/Server-Side-Coding/PHP/html-forms-php/page1.html

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

On Mar 6, 6:55 pm, geoffcox <geoffa...@gmail.com> wrote:
> Hello
>
> I cannot seem to get my head round how to deal with multiple selects
> and form.serialize
>
> I have, say,
>
> <select name="colour_value" size= "2" multiple="multiple">
> <option value="green">green</option>
> <option value="blue">blue</option>
> <option value="yellow">yellow</option>
> <option value="white">white</option>
> </select>
>
> How do select both blue and white and use form.serialize to pass these
> values to a php file which will insert the values into mysql? I have
> seen that I should use colour_value[] but what next?
>
> Thanks!
>
> Geoff

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to