Back to Top

Polldaddy Polls Callback after Voting

Previous Post:

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:

  1. <script type="text/javascript" charset="utf-8">
  2.     var pd_callback = function(){
  3.         alert('Your vote has been counted!');
  4.     };
  5. </script>
  6. // 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 here

The 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:

  1. <script type="text/javascript" charset="utf-8">
  2.     var pd_callback = function(){
  3.         alert('Your vote has been counted!');
  4.     };
  5. </script>
  6. <?php
  7. $polldaddy_polls = bwp_get_polls(0, 'created', 'desc');
  8. foreach ($polldaddy_polls as $poll)
  9. {
  10. ?>
  11.     <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/<?php echo $poll->id; ?>.js"></script>
  12.     <noscript>
  13.         <a href="http://polldaddy.com/poll/<?php echo $poll->id; ?>/"><?php echo $poll->content; ?></a>
  14.     </noscript>
  15. <?php
  16. }
  17. ?>
<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:

  1. <?php
  2. $polldaddy_polls = bwp_get_polls(0, 'created', 'desc');
  3. foreach ($polldaddy_polls as $poll)
  4. {
  5. ?>
  6.     <script type="text/javascript" charset="utf-8">
  7.         var pd_callback_<?php echo $poll->id; ?> = function(){
  8.             alert('Your vote for Poll <?php echo $poll->id; ?> been counted!');
  9.         };
  10.     </script>
  11.     <script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/<?php echo $poll->id; ?>.js"></script>
  12.     <noscript>
  13.         <a href="http://polldaddy.com/poll/<?php echo $poll->id; ?>/"><?php echo $poll->content; ?></a>
  14.     </noscript>
  15. <?php
  16. }
  17. ?>
<?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 ;) .

Print Article Trackback Trackback to this Article   Subscribe to Comments RSS Subscribe to Comments RSS

Speak Up Your Mind!

An asterisk (*) indicates a required field and must be filled.




  • Web page and e-mail addresses turn into links automatically.
  • Wrap codes in: <code lang=""></code> or <pre lang="" extra="">
  • Lines and paragraphs break automatically.

Next Post: