What is the best, in Perl, way to get the selected values of a multiple select form field?
<select name="mult" multiple="multiple">
<option value="1">Opt. 1</option>
<option value="2">Opt. 2</option> <!-- selected -->
<option value="3">Opt. 3</option>
<option value="4">Opt. 4</option> <!-- selected -->
<option value="5">Opt. 5</option>
</select>
I get regular fo开发者_StackOverflow中文版rm fields like this: $param1 = param('param1');
If you are using the CGI Module (and I really hope you are) then you can access the multiple values by assigning the param hash to an array and CGI does the rest. So in your example:
my @mult = $q->param('mult');
will store the selected values (2, 4)
in the @mult
array.
精彩评论