|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
ok i have a cgi poll up at my website. you can check it out at http://www.artificialg.net the poll works fine, but i want the results to be displayed on the homepage instead of a separate page being loaded with the reuslts of the cgi poll. essentially, i want my homepage to reload once someone has voted and display the results of the poll where the poll question is before someone votes. does anyone know how i can accomplish this? javascript possibly? i've done some extensive searching on the internet, but couldn't find anything. thanks in advance.
here is the cgi code in case it helps: #!/usr/local/bin/perl if ($ENV{'REQUEST_METHOD'} eq 'POST') { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); # Load the FORM variables foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } } print "Content-type: text/html\n\n"; if(-e "poll.dat") { open(POLL, "poll.dat"); } while(<POLL>) { push(@poll, $_); } close(POLL); @lines = ("1"); foreach $each_line (@lines) { $this_line = "line" . $each_line; $$this_line = $poll[$each_line-1]; chop($$this_line); } if($line1 eq " ") { $line1 = "0\t0\t0"; } @line1_answers = split(/\t/, $line1); if($FORM{'QUESTION'} eq "yes") { $line1_answers[0]++; } elsif($FORM{'QUESTION'} eq "no") { $line1_answers[1]++; } open(POLL, ">poll.dat"); print POLL "$line1_answers[0]\t$line1_answers[1]\n"; close(POLL); print "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>artificialg.net</TITLE>\n"; print "</HEAD>\n"; print "<BODY BGCOLOR=white>\n"; print "<font face=arial color=#0000bb size=1>\n"; print "do you recycle?<BR><BR>\n"; print "<font face=arial color=#0000bb size=1>\n"; print "yes "; print " \n"; print $line1_answers[0] / ($line1_answers[0] + $line1_answers[1])*100; print " %"; print "<BR><BR>\n"; print "no "; print " \n"; print $line1_answers[1] / ($line1_answers[0] + $line1_answers[1])*100; print " %"; print "</TD>"; print "</BODY>\n"; print "</HTML>\n"; |
|
#2
|
||||
|
||||
|
I've seen polls out there that do this. Maybe take another look. If you're adventurous, you can try to hack this one up. Basically, what you'd need to do would be to write a cookie whenever somebody votes in the poll. Then you'd modify the poll display code so that if a given person's got the cookie, it displays the results instead of the poll. On submit, reload the home page, the cookie'll be there, and the results will be displayed. Further, for as long as the cookie's there, repeat visitors will see the results rather than the poll itself.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > need help with cgi poll |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|