The way I've handle this situation in the past is to POST directly to vote.cgi. vote.cgi then records the vote and who voted (by either cookie, or some other tracking means). vote.cgi then sends a redirect header back to index.shtml.
When index.shtml includes vote.cgi again, the script should realize that the user has already voted and will post only the results.
some pseudocode:
# ...
$action = $query->param('action');
$voted = hasuservoted();
if ($action eq "show")
$voted ? show_results() : show_poll();
}
elsif ($action eq "vote" && !$voted) {
vote();
}
else {
error("no valid action");
}
sub show_poll {
# display the poll so the user can fill it in.
}
sub show_results {
# show the poll results -- user can no longer vote
}
sub vote {
# record the user's vote
# record who voted
# redirect to index.shtml
}
sub hasuservoted {
# returns 1 if user has voted
# returns 0 if user has no voted
}
Something like that. In index.shtml you'd include
vote.cgi?action=show. Your poll html should include the hidden field
<input type="hidden" name="action" value="vote">.
HTH.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.