Re: REPOST
by "Darrell King" <darrell(at)webctr.com>
|
Date: |
Wed, 19 Feb 2003 08:05:36 -0500 |
To: |
"HWG" <hwg-techniques(at)mail.hwg.org> |
References: |
hwg |
|
todo: View
Thread,
Original
|
|
Greg is correct: it's up to the script that accepts the POST. The
formatting of the results is not subject to a universal set of rules, but
rather it is up to the script author.
A common means of handling multiple fields with the same name in Perl, for
instance, is to concatenate them with a delimiter of some kind. For
instance, this:
<checkbox name='box' value='1' />
<checkbox name='box' value='2' />
Might result in this in the script:
Name: $box
Value: "1\02"
The values 1 and 2 have been joined by the delimiter '\0'. If you used a
comma, you could end up with a comma-delimited string right away, although
that isn't often done because the submitted values may themselves hold
commas (such as with freestyle textareas).
You can also load values with the same name into an array, where each
element would contain 1 value. Then, using join():
$list = join(', ',$box);
Using PHP, you can force an array of elements by using brackets ([]) with
the field name in the HTML itself:
<checkbox name='box[]' value='1' />
<checkbox name='box[]' value='2' />
The resulting array can then be turned into a comma-delimited list easily
enough within the PHP script:
$list = join(', ',$_POST['box']);
If you leave off the double bracket:
<checkbox name='box' value='1' />
<checkbox name='box' value='2' />
....you would have the value of last item checked overwriting any previous
ones unless you use special handling, as described below.
>From the description, what is happening is that the PHP script is set up to
handle the standard, expected types of POST input. This is quite likely in
PHP as that language does a lot of the work for the programmer when it comes
to processing input, so things such as the unique names or the array setup
can be easily handled. Having multiple checkboxes with the same name but
without using brackets is something that would take a little custom work to
handle...something like this, maybe:
foreach ($_POST as $k => $v) {
if (is_array($v)) $INPUT[$k] = join(', ', $v);
else {
if (isset($INPUT[$k])) $INPUT[$k].= ', ';
$INPUT[$k] .= $v;
}
}
The array $INPUT now holds the values from the form, and any fields that
have multiple instances have been turned into comma-delimited strings. For
instance, $INPUT['box'] now holds "1, 2" for either of the HTML examples
above.
That would actually initiate a warning because of the last line ($INPUT[$k]
.= $v;) being a concatenation for new variables, but it's the right idea.
PHP is easy enough to make changes to, but the key to this question is that
you need to make those changes to the PHP script itself and not expect to be
able to accomplish it via alterations to the HTML form only.
D
----- Original Message -----
From: cbirds
To: Greg Hart ; HWG
Sent: Wednesday, February 19, 2003 1:08 AM
Subject: Re: REPOST
Greg Hart tapped out this message on 2/19/2003 12:45 AM
>In short, the HTML form sends the values. It cares not how they are
>displayed on the other side, that's not its job. That's my guess anyway,
>since it's work for me with the same name. And I know it's just academic,
>since cbirds seems to have resolved his problem anyway. Just had to
comment.
I believe the form is sending the data via php. I just set up the form,
not the server side stuff, so that is all I can tell you.
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA