Gossamer Forum
Home : General : Perl Programming :

problem passing form variables

Quote Reply
problem passing form variables
this has to be something simple! i have a form that builds five radio fields: column-1, column-2, etc. when the form is submitted, i want to display the value that was selected. while testing, i'm using the following:
Code:
while ($count < 6) {
print qq|<tr><td>column-$count $in{'column-$count'}</td></tr>|;
$count++;
}
foreach $key (sort keys %in) {
if ($key =~ /column/) {
print "<tr><td>$key: $in{$key}</td></tr>\n";
}
}
the display looks like this:
column-1
column-2
column-3
column-4
column-5
column-1 Title
column-2 Description
column-3 Category
column-4 Updated
column-5 Approved

the first one doesn't work but is the one i want to use! the second one does work (displays the values selected) but i don't want to use it for other reasons. i can't figure out what's wrong with $in. i've tried it with and without the single quotes with same result.
Quote Reply
Re: [delicia] problem passing form variables In reply to
Without trying and thinking about pros and cons of your approach I think I remember that I had something similar which was more like:

Code:
$in{"column-" . $count}

or

Code:
$in{'column-' . $count}

Not sure but maybe it helps.

Regards
Quote Reply
Re: [delicia] problem passing form variables In reply to
Got curious and gave it a try. My example works but yours as well after you modify
Code:
$in{'column-$count'}
from single to
Code:
$in{"column-$count"}
double quotes. Nevertheless I think it is generally more explicit to do
Code:
$in{'column-' . $count}
Quote Reply
Re: [el noe] problem passing form variables In reply to
i tried all of those but the only one that worked for me was
Code:
foreach $key (sort keys %in) {
if ($key =~ /column/) {
print "<tr><td>$key: $in{$key}</td></tr>\n";
}
}
so i decided to use this
Quote Reply
Re: [delicia] problem passing form variables In reply to
Code:
while ($count < 6) {
print qq|<tr><td>column-$count $in{'column-$count'}</td></tr>|;
$count++;
}
You are using single quotes - that tells perl to NOT interpret. So it would be literally looking for variable called "column-$count". The easiest way would just be:

Code:
while ($count < 6) {
print qq|<tr><td>column-$count $in{"column-$count"}</td></tr>|;
$count++;
}

i.e using " instead of ' in the $in{} part :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] problem passing form variables In reply to
thanks! i think i'll leave as-is unless something else breaks... moving on to other things.
Quote Reply
Re: [delicia] problem passing form variables In reply to
haha NP. Here is a simple explanation as to what its doing:

https://users.cs.cf.ac.uk/dave/PERL/node18.html

Basically, using ' around strings allows you to use @ $ etc without it causing issues (for example $45 would try and find a variable called $45, rather than just printing it)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!