Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^5: HTML::Template with checkbox

by rpnoble419 (Pilgrim)
on Sep 06, 2012 at 04:17 UTC ( #991997=note: print w/replies, xml ) Need Help??

in reply to Re^4: HTML::Template with checkbox
in thread HTML::Template with checkbox


This is a down and dirty example. You should taint the data in production. Here is my example.

HTML file

<html lang="cs"> <head> </head> <body> <form action=""> <input type="checkbox" name="field" value="Red"> Red<br> <input type="checkbox" name="field" value="Blue"> Blue<br> <input type="checkbox" name="field" value="Green"> Green<br> <input type="checkbox" name="field" value="Yellow"> Yellow<br> <input type="submit"> </form> </body> </html>

Perl Code

#!/usr/bin/perl use strict; use CGI qw/:standard :html4/; use CGI::Carp qw ( fatalsToBrowser ); my $query = new CGI; print $query->header(); &logit($0." has started" ); &logit("======================="); &logit($0." ".query_string()); my @values = $query->param('field'); my $ColorCount=@values; print "Colors Selected: ".$ColorCount."<br>"; foreach my $item (@values) { print "Colors: ".$item."<br>"; } exit;


Colors Selected: 4 Colors: Red Colors: Blue Colors: Green Colors: Yellow

I hope this helps

Replies are listed 'Best First'.
Re^6: HTML::Template with checkbox
by bebewinla (Novice) on Sep 06, 2012 at 22:58 UTC

    Hi rpnoble419, Thanks for you sample program. But I still having trouble of getting the values "field". I used TMPL_LOOP NAME to display a list of filenames & checkboxes next to it. This is all done with template & print $template->output. I defined the checkbox inside a form, also a "submit" button.

    <form method="post" action="index.cgi"> <td><input type="checkbox" name="field" <TMPL_VAR NAME="check"> value +="<TMPL_VAR NAME = "fn">"></td> </form>
    when "submit" is click, my main script index.cgi would check check for the command then call a subroutine "download"
    sub download { my @anything = $q->param(); my $anything_num = @anything; my @anyfetch = $q->param("field"); my $anyfetch_num = @anyfetch; print "anything_num = $anything_num"; print "anyfetch_num = $anyfetch_num"; }

    both of print give me Zero values, it does not seem like the subroutine is able to fetch the input field from my table html page. I am not sure why. I have the concept, but somehow when applying to coding, it's different story.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991997]
[LanX]: how difficult is IP spoofing in the intranet?
[Your Mother]: I'm curious to hear the answer.
[LanX]: never mind
[LanX]: we have a vulnaribility task force in the company flooding our servers with fake attacks
[LanX]: I called them complaining about the load, and they told me to just ignore their IP
[LanX]: ... in the logs
[LanX]: but I tend to just reject it by an apache rule
[shmem]: LanX: start a DDOS upon their servers :-P

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2018-03-19 14:29 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.