Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

TMPL_VAR with selection box

by bebewinla (Novice)
on Nov 08, 2012 at 01:41 UTC ( #1002786=perlquestion: print w/ replies, xml ) Need Help??
bebewinla has asked for the wisdom of the Perl Monks concerning the following question:

Here is my html file using tmpl_var to display a list of files names, selection of time, selection type

<table> <TMPL_LOOP NAME="files_loop"> <tr> <td><TMPL_VAR NAME ="index"></td> <td><TMPL_VAR NAME ="fn"> </td> <td class="form"><select name="files234p"> <option value = "0">- Select -</option> <option value = "1 ">1 Sec Delivery</option> <option value = "10 ">10 Sec Delivery</option> <input type="hidden" name="file" value="<TMPL_VAR NAME="fn">"> + </select></td> </tr></TMPL_LOOP></table>

In my cgi script, I was able to display the output in a format of a table, 1st column - index #, 2nd column-list of filenames, 3rd column- it's a selection box of "time". my problem is getting the filenames using $q->param.

foreach my $value ($q->param('files234p')) { if ($value != 0) { my $filen = $qq->param('file'); print FOUT $filen," ",$value, "\n"; $i++; } }

when I select 1st row selection box with 1 sec, then 2nd row selection box with 10 sec. 3rd file with 1 sec. my output shows :

file1 1 file1 10 file1 1 it should be : file1 1 file2 10 file3 1

I am not getting filenames correctly, it stays as the 1st one. Can any one help please. is it the $q->param incorrectly used

Comment on TMPL_VAR with selection box
Select or Download Code
Re: TMPL_VAR with selection box
by choroba (Abbot) on Nov 08, 2012 at 01:48 UTC
    What templating engine do you use? Does it increment fn for you automatically?
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Hi Choroba, I am not sure the answer of your question. not sure if it increment each time, but when I do this

      <input type="hidden" name="file" value="<TMPL_VAR NAME="fn">"> change it to <input type="text" name="file" value="<TMPL_VAR NAME="fn">">

      so instead of type as "hidden" I changed to "text" for debug purpose,it displayed correctly each row with different filename, so it looked like my "fn" was generated correctly, it just the read in function in my script not working (I am not sure)

        I use the standard HTML::Template
Re: TMPL_VAR with selection box
by Anonymous Monk on Nov 08, 2012 at 02:23 UTC

    it should be

    Based on what?

      my display is like this(more or less like table display

      file1 pulldown_selection#1 file2 pulldown_selection#2 file3 pulldown_selection#3 ..... so when I select the pulldown#1, I selected 1 sec .... the pulldown#2, I selected 10 sec .... the pulldown#3, I selected 1 sec

      There is a submit button at the end, in my cgi script, I need to find out what selections I made, which should be

      file1 1 file2 10 file3 1 but I got is file1 1 file1 10 file1 1

      filename "file#" not change at all

        filename "file#" not change at all

        In the template you posted there is nothing included that changes the name of the form element, it is hardcoded to "files234p"

        it will always be files234p"

        The name attribute of your select tag is hardcoded to files234p

Re: TMPL_VAR with selection box
by choroba (Abbot) on Nov 08, 2012 at 08:37 UTC
    All the "file" inputs are named the same. Therefore, you should use param in list context to get the list of all the values:
    my @filen = $qq->param('file');
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1002786]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-09-20 03:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (152 votes), past polls