Hello Monks,

I'm having some issues processing a Multiple Select box with Perl, and who else better to leverage than the Monks!

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ +/www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Test Form</title> </head> <body> <form method="post" action="/cgi-bin/test_form.cgi"> Function:<br/> <br/> <select name="Blah[]" multiple="multiple"> <option value=""></option> <option value="Blah1">Blah1</option> <option value="Blah2">Blah2</option> <option value="Blah3">Blah3</option> <option value="Blah4">Blah4</option> <option value="Blah5">Blah5</option> </select> <br/><br/> <input type="submit" value=" Submit " /> </form> </body> </html>
Perl:
#!/usr/bin/perl -w use strict; my ($buffer, $pair, $var, $payload, $i); my (@pairs); my (%POST); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($var, $payload) = split(/=/, $pair); $payload =~ tr/+/ /; $payload =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $POST{$var} = $payload; } foreach $i ($POST{Blah}) { print "Blah: ".$i."<br/>\n"; }
This is what I thought would work.

I've tried various ways of retrieving the data, and I either get nothing back or I only get back the last element.

Thanks for any help!

- Justin

In reply to Processing a multiple="multiple" <select> by jpk236

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.