Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

checkbox name processing

by vrempire (Sexton)
on Aug 09, 2000 at 11:10 UTC ( [id://26971]=perlquestion: print w/replies, xml ) Need Help??

vrempire has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys,I have a problem right here which I tried to solve but can't.I have to solve this before I can proceed further. Hope u guys can help me. In my first perl script,file1.pl,I put
foreach $filename(@latest) { if (-f $filename) { print "<input type=checkbox name=$filename value=1>"; open FILE, "$filename" or die "Cannot open:$!\n"; while(<FILE>) { #process the file } close FILE; }
so,how I want to make,when the user click the submit button,if the checkbox is checked,then the $filename will be print out at the next perl script that is called,which is file2.pl.If I already put the @latest array inside file2.pl,then it should be no problem.But how if there is no @latest in the file2.pl?I nearly got it,but it only print the last $filename that I checked,not all that I checked.Maybe I could put all the $filename that been checked inside an array such as @selected after the user click the submit button.How to do that? thanks for your concern.

Replies are listed 'Best First'.
Re: checkbox name processing
by ColtsFoot (Chaplain) on Aug 09, 2000 at 14:03 UTC
    vrempire the response was in fact from me Coltsfoot but I had forgotten
    to login ):
    In the example when the "Submit" button is selected the default action is to call
    the same script again. If you want to have an action='http://your.site.com/cgi-bin/anotherperlfile.pl
    then you should perform the code
    if ($page->param('submit')) { @files = grep {defined CGI::param($_) or CGI::param($_) ne ' +'} CGI +::param(); print @files; #Do your code here..... }
    in that file then @files will be available in that file
    Hope that is clear
Re: checkbox name processing
by Anonymous Monk on Aug 09, 2000 at 12:14 UTC
    If I understand the problem correctly what you are trying
    to do is when the submit button is hit is to find the filenames
    of the files that have been checked
    In the following piece of code, when the submit button is hit
    the array @files will contain the names of the files checked and the
    string 'submit'
    #!/usr/bin/perl -w use CGI; $page = new CGI; print $page->header(); print $page->start_html(); if ($page->param('submit')) { @files = grep {defined CGI::param($_) or CGI::param($_) ne ''} CGI +::param(); print @files; exit; } print $page->startform(); @latest = qw(one two three); foreach $fname(@latest) { print qq($fname <input type='checkbox' name='$fname' value='$fname +'>); print qq(<br>\n); } print qq(<input type='submit' name='submit' value='Submit'); print $page->endform(); print $page->end_html();
    Hope this helps
      Thanks for your reply,I really appreciate it.So,for the array @files,is the array also being send to the next cgi file to process when the submit button is clicked,or is the array @files is still inside the current cgi file? I prefer that the @files can be send also to the next cgi file,so I can process it inside the new one. Thanks again.
Re: checkbox name processing
by vrempire (Sexton) on Aug 09, 2000 at 11:43 UTC
    I changed the print "<input type=checkbox name=$filename value=1>"; to print "<input type=checkbox name=select value=$filename>"; but it still don't solve yet,since it show only the last $filename checked.
Re: checkbox name processing
by vrempire (Sexton) on Aug 09, 2000 at 16:13 UTC
    Thank you Coltsfoot.you realy help me a lot.well,after I read your reply,I think that maybe I should just use the same script,instead of link to another cgi file.anyway,thank you very much.You have open the door to me. :>
RE: checkbox name processing
by turnstep (Parson) on Aug 09, 2000 at 19:27 UTC

    A quick note: you should quote all the attributes in your HTML tags. To do this, you will need to use some other quoting mechanism besides a double quote ("). Here is one way:

    print qq[<input type="checkbox" name="$filename" value="1">\n];
    Note the newline addition to make the source code more readable after the HTML page is output. I would also switch the order of the print and the open statment, so that if the open fails and the program dies, the line is not printed first.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (10)
As of 2024-04-16 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found