Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 19th, 2004, 09:47 PM
artificialg artificialg is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 artificialg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question need help with cgi poll

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 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";

print $line1_answers[0] / ($line1_answers[0] + $line1_answers[1])*100;

print "&nbsp;%";

print "<BR><BR>\n";

print "no ";

print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";

print $line1_answers[1] / ($line1_answers[0] + $line1_answers[1])*100;

print "&nbsp;%";
print "</TD>";


print "</BODY>\n";
print "</HTML>\n";

Reply With Quote
  #2  
Old July 20th, 2004, 06:42 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > need help with cgi poll


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT