PHP include: add a poll to a PHP page
Show a poll directly inside a PHP page with phppoll(). Use the newest or a random poll, set theme and accent options and fix missing styles.
If your website is written in PHP and runs on the same server as PHPPoll, you can print a poll straight into your page with one function call. The poll becomes part of your page – no iframe.
Basic usage
<?php require_once '/home/user/public_html/poll/phppoll.php'; ?>
<!-- ... your page ... -->
<?php phppoll('POLL_ID'); ?>
- Add the
require_onceline once, near the top of your PHP file. Use the absolute path shown on the Embed & share page. - Call
phppoll('POLL_ID')where the poll should appear.
Show the newest or a random poll
<?php phppoll('latest'); ?> // your newest open poll
<?php phppoll('random'); ?> // a random open poll
Perfect for a sidebar widget that always shows something fresh.
Options
<?php phppoll('abc123', array(
'theme' => 'dark', // light, dark or auto
'accent' => '#e11d48' // accent color
)); ?>
How it behaves
- The stylesheet and script of PHPPoll are added automatically the first time you call the function. Several polls on one page share them.
- With JavaScript the poll updates in place after voting. Without it, the form posts to
vote.phpand the visitor returns to the same page. - Draft polls are not shown, and a missing poll prints nothing.
- All PHPPoll functions start with
pp_, so they do not clash with the functions of your site.
When the poll has no styling
PHPPoll builds the address of its CSS file from the location of its folder. If the poll appears without styles, open the admin panel once (it remembers the address), or set the Script URL in Settings → Public site. See Settings and Troubleshooting.
Your website does not need to be inside the PHPPoll folder. It only needs to be able to read the PHPPoll files on the same server.
Last updated