Forum Moderators: coopster & phranque

Message Too Old, No Replies

This is probably an easy question but.

Easy question

         

rcapilli

8:18 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



I have 2 pages. One page will dynamically build Input fields:
print "<tr><td><input type='text' name='TextArea_$filename_open' value='Test></tr></td>";

On the page that this code is being submitted to I am trying to get each dynamically built field (from above) and place it into a variable via a loop.

foreach $files (@thefiles)
{
$NewTextEnteredForPics = $query->param('TextArea_$filename'); # comes from the Input text box
}

When the second page runs from the submit button on the first page, nothing is in [$NewTextEnteredForPics]. In fact it is empty. BUT I do have one static input form field on page 1

print "<input type='hidden' name='TheDirectoryEntered' value='$DirectoryTextBox'>";

and on the second page I have

my $DirectoryEntered = $query->param('TheDirectoryEntered');

This works. I can print out the contents of [$DirectoryEntered] But if I build several text boxes dynamically and populate them with different names then when it is submitted to the next page I cannot get the contents within the text boxes that I submitted. Why is this happening? What is the difference building a statis NAMED text box vs. one that is built in a loop?

Thanks for any help you can give.
Rob-

KevinADC

8:54 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



it's probably a problem with using underscores to try and insert $filename into a text string, you can't do that as underscores are a valid scalar character.

a-zA-Z0-9_ are all valid for scalar names


$filename and $filename_open are both valid scalars, so your code is looking for $filename_open and not finding it (I assume).

use concatenation or commas to build your text string:

print "<tr><td><input type='text' name='TextArea_" . $filename . "_open' value='Test></tr></td>";

or:

print "<tr><td><input type='text' name='TextArea_",$filename,"_open' value='Test></tr></td>";

although to me concatenation is more logical in this context. Makes sense?

KevinADC

8:58 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



also, this loop through your array seems to not be associated with what you are attempting:

foreach $files (@thefiles)
{
$NewTextEnteredForPics = $query->param('TextArea_$filename'); # comes from the Input text box

$filename maybe should be $files? And no single quotes around params() that have scalars in them:

$query->param("TextArea_$filename");

otherwise you kill the interpolation of the scalar and it becomes a literal string.

rcapilli

1:28 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



WHOA! You were totally correct. My issue was

$NewTextEnteredForPics = $query->param('TextArea_$filename'); # comes from the Input text box

I cannot use single quotes here it has to be double quotes.

$NewTextEnteredForPics = $query->param("TextArea_$filename"); # comes from the Input text box.

and I took out the underscore in [TextArea_$filename_open] so it looks like [TextArea_$filename].

Thank you very much for the info. I feel like 10lbs has come off my shoulders. :)

rocknbil

9:07 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or just toothpick (escape) it. 'TextArea\_$filename_open' :-)

KevinADC

9:27 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



yes, that would also work :)