[thelist] Phorm and Checkboxes

Keith cache at dowebscentral.com
Mon Jan 6 21:46:01 CST 2003


It's been many moons, perhaps years, since I've found .jeff in technical
error, but this post was.

>that's not true at all.  if they all have the same name and item 1 and item
>2 are checked then, if php/phorm is doing things properly, $question_01
>should be 'item 1,item 2'.  the browser simple collects all the successful
>controls, combines same named ones (regardless of the type of control --
>select-one, select-multiple, checkbox, text, password, hidden, and textarea)
>into a comma-delimited list of values and sends them to the server.

This comma-delimited string of values may *appear* to be what was
transmitted once input has been parsed by CF, ASP, PHP, CGI.pm or some
other programmer's crutch, but it's not how data moves.

For a multiple select, or a series of same-named checkboxes, each VALUE
arrives at the server separately, with it's paired NAME. The name is not
the control, the value determines whether the element gets sent, then it's
name is added to that pair, without regard to whether there is already an
exiting pair by the same name in queue to submit.

If you capture the raw stream from STDIN you'll see a series of name=value
pairs separated by & signs.

<select multiple name=items size=3>
<option value=item1>Item1
<option value=item2>Item2
</select>
<input type=checkbox name=things value=thing1><br>
<input type=checkbox name=things value=thing2><br>

Select all "items" and check all "things", submit and read raw STDIN into a
variable

read(STDIN, $input, $ENV{'CONTENT_LENGTH'});

and you get

items=item1&items=item2&things=thing1&things=thing2

I use same-named checkboxes a lot so my standard parse input subroutine
automatically captures all input into a NAME named array and then converts
to the comma-delimited (or preferably a tilde-delimited) string that  .jeff
alludes to

@pairs = split(/&/,$input);
foreach $pair (@pairs){
   ($name, $value) = split(/=/,$pair,2);
   push(@$name,$value);
   $$name=join(",",@$name);
}

Using the above form you get what .jeff describes

items=item1,item2
things=thing1,thing2

but, that is not how the browser sends the data......



Keith
====================
cache at dowebscentral.com




More information about the thelist mailing list