
2huskys
New User
Dec 7, 2010, 8:44 AM
Post #1 of 2
(1673 views)
|
Cant get my checkboxes to display all the users selected ones
|
Can't Post
|
|
I have to create a newsletter prefrence thing where the user inputs their email and selects the newsletters they wish to receive via checkbox. The next page will output the email and display their prefrences in alphabetical order. I am using an array for the checkboxes but for some reason it only outputs the first one selected in the array rather than all of them. Is there away to use the param function to put the selected results in an array and sort them and then use that to output them. why is only one being displayed rather than them all. below is the code for the first page.#!/strawberry/perl/bin/perl use CGI ':standard'; print header, start_html('Newsletter Prefrences'); @prefrences = ("Comedy", "Current Affairs", "Music", "Documentary", "Soaps" ); print start_form ( { action=>'http://localhost/cgi-bin/assignmentform2.cgi'} ); print "please enter your email "; print '<INPUT TYPE=Text SIZE=30 NAME=email>'; print p, "please select which newsletters you would like to receive"; for ( $item = 0; $item <= 4; $item++ ) { print "<INPUT TYPE=\"checkbox\" NAME=\"prefrence\" VALUE=$item>", @prefrences[$item], "\n"; } print p, submit, reset; print end_form, end_html; Below is the code for the second page#!/strawberry/perl/bin/perl use CGI ':standard'; use CGI::Carp "fatalsToBrowser"; print header, start_html("your prefrences"); $logfile=">>logfile.txt"; open (OUTFILE, $logfile ) || die "Cannot open $logfile: $!"; @infile = <INFILE>; print $infile[0]; print $infile[2]; close (INFILE); @prefrences = ("Comedy", "Current Affairs", "Music", "Documentary", "Soaps" ); $selection = param('email'); if ( $selection eq "" ) { print("You did not input an email please input one!"); } else { print ("Your email is $selection"); } $prefrence = param('prefrence'); print p, "You have selected to receive $prefrences[$prefrence]"; print OUTFILE "$selection/$prefrences[$prefrence]\n"; print p, 'Just Logged:', br,"$selection/$prefrences[$prefrence]"; close (OUTFILE); print end_html; any help would be great thanks
|