Re: can you pass an array in a form in Perl



John wrote:
Is the following possible in Perl?

print "<form>";
print "<input type='hidden' name='cities' value='@industries'>";
print </form>";

Of course it's possible. What happened when you tried it?

Now, as to whether or not the results of the above are what you wanted,
well, only you know that. Because you didn't bother to tell us what
results you're hoping to achieve.

I want to pass an array as a hidden value.

This is non sensical. A "hidden value" in an HTML form is a string.
What do you mean you want to pass an array?

If you're hoping that your cgi script returns an array for
param('cities'), then no, the above will not do what you want. There
are, however, several ways to accomplish that goal.

Method 1: your HTML as above, and then just split the results of the
param call on whitespace. This of course assumes that no elements of
@industries contain whitespace themselves:

my @cities = split ' ', param('cities');

Method 2: Print out one hidden field for every value of @industries,
and then use the param() call in a list context:

for my $industry (@industries) {
print "<input type='hidden' name='cities' value='$industry'>\n";
}
#......
my @cities = param(@cities);

I've removed other parts for clarity.

While your attempt at being clear is appreciated, it is almost always
better to post a SHORT but COMPLETE script that demonstrates your
error.

Paul Lalli

.