Polldaddy Polls Callback after Voting
Needless to say, Polldaddy Poll can be a very powerful poll system for your website/blog. Using its API, you can display polls however you like, and in any order you need. But did you know you can also add a callback function that will be executed after a successful vote? You can make such thing happen by defining the pd_callback variable, as shown below:
- <script type="text/javascript" charset="utf-8">
- var pd_callback = function(){
- alert('Your vote has been counted!');
- };
- </script>
- // Show the rest of the poll script here
<script type="text/javascript" charset="utf-8">
var pd_callback = function(){
alert('Your vote has been counted!');
};
</script>
// Show the rest of the poll script hereThe snippet should be self-explanatory
. Now if you used my BWP Polldaddy Polls plugin or my Polldaddy class in the above mentioned article, just add the callback before the foreach loop:
- <script type="text/javascript" charset="utf-8">
- var pd_callback = function(){
- alert('Your vote has been counted!');
- };
- </script>
- <?php
- $polldaddy_polls = bwp_get_polls(0, 'created', 'desc');
- foreach ($polldaddy_polls as $poll)
- {
- ?>
- <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/<?php echo $poll->id; ?>.js"></script>
- <noscript>
- <a href="http://polldaddy.com/poll/<?php echo $poll->id; ?>/"><?php echo $poll->content; ?></a>
- </noscript>
- <?php
- }
- ?>
<script type="text/javascript" charset="utf-8">
var pd_callback = function(){
alert('Your vote has been counted!');
};
</script>
<?php
$polldaddy_polls = bwp_get_polls(0, 'created', 'desc');
foreach ($polldaddy_polls as $poll)
{
?>
<script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/<?php echo $poll->id; ?>.js"></script>
<noscript>
<a href="http://polldaddy.com/poll/<?php echo $poll->id; ?>/"><?php echo $poll->content; ?></a>
</noscript>
<?php
}
?>You can also have a unique callback function for each poll, but this time you will have to put the callback function inside the foreach loop, like so:
- <?php
- $polldaddy_polls = bwp_get_polls(0, 'created', 'desc');
- foreach ($polldaddy_polls as $poll)
- {
- ?>
- <script type="text/javascript" charset="utf-8">
- var pd_callback_<?php echo $poll->id; ?> = function(){
- alert('Your vote for Poll <?php echo $poll->id; ?> been counted!');
- };
- </script>
- <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/<?php echo $poll->id; ?>.js"></script>
- <noscript>
- <a href="http://polldaddy.com/poll/<?php echo $poll->id; ?>/"><?php echo $poll->content; ?></a>
- </noscript>
- <?php
- }
- ?>
<?php
$polldaddy_polls = bwp_get_polls(0, 'created', 'desc');
foreach ($polldaddy_polls as $poll)
{
?>
<script type="text/javascript" charset="utf-8">
var pd_callback_<?php echo $poll->id; ?> = function(){
alert('Your vote for Poll <?php echo $poll->id; ?> been counted!');
};
</script>
<script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/<?php echo $poll->id; ?>.js"></script>
<noscript>
<a href="http://polldaddy.com/poll/<?php echo $poll->id; ?>/"><?php echo $poll->content; ?></a>
</noscript>
<?php
}
?>Of course, you are not limited to those simple alert callbacks. With all the poll data you have (thanks to my plugin or Polldaddy class =P), you can virtually do anything
.







Recent Opinions