PHPackages                             mateusz/silverstripe-polls - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mateusz/silverstripe-polls

ActiveSilverstripe-module[Utility &amp; Helpers](/categories/utility)

mateusz/silverstripe-polls
==========================

Poll module for SilverStripe

1178116[9 issues](https://github.com/mateusz/silverstripe-polls/issues)[9 PRs](https://github.com/mateusz/silverstripe-polls/pulls)PHP

Since Feb 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mateusz/silverstripe-polls)[ Packagist](https://packagist.org/packages/mateusz/silverstripe-polls)[ RSS](/packages/mateusz-silverstripe-polls/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Polls module
============

[](#polls-module)

[![Build Status](https://camo.githubusercontent.com/5f6bae8da82e9821cffaade76001a26b4901554126d9bda7a3c473fcdefae5f0/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6d61746575737a2f73696c7665727374726970652d706f6c6c732e706e67)](http://travis-ci.org/mateusz/silverstripe-polls)

Maintainer
----------

[](#maintainer)

[Mateusz Uzdowski](mailto:mateusz@silverstripe.com)

Requirements
------------

[](#requirements)

master: SilverStripe 3.0.x 0.1: SilverStripe 2.4.x

Installation
------------

[](#installation)

1. Include the module folder in your project root folder and rename it to "polls"
2. Rebuild database schema (dev/build?flush=1)

Features
--------

[](#features)

- By default, each visitor, determined by browser cookie, can only vote once
- Uses [Google chart API](http://code.google.com/apis/chart/)
- Supports single and multiple-choice polls

Usage
-----

[](#usage)

### CMS usage

[](#cms-usage)

1. Log in the CMS
2. Go to the *Poll* section
3. Create a poll, press *Add*, then add a few poll options
4. The further steps depend on how the PollForm has been implemented

### Connect Poll object with PollForm

[](#connect-poll-object-with-pollform)

The PollForm knows how to render itself, and is able to render both the selection form and the chart. It needs to get a Poll object as its input though, and it's up to you to provide it: it will depend on your project how you will want to do this.

Here is the most basic example of how to associate one Poll with each Page:

```
class Page extends SiteTree {
	static $has_one = array(
		'Poll' => 'Poll'
	);

	...

    function getCMSFields() {
        $fields = parent::getCMSFields();

        $polls = Poll::get();
        if ($polls) {
            $fields->addFieldsToTab('Root.Main', array(
                DropdownField::create('PollID', 'Poll', $polls->map(), $this->PollID)->setEmptyString('--- Select a poll ---'),
            ));
        }
        else {
            $fields->addFieldsToTab('Root.Main', array(
                new LiteralField('Heading', 'No polls available'),
				new LiteralField('PollID', 'There are no polls available. Please use the polls
					section to add them.')
            ));
        }

        return $fields;
    }

	...
}
```

Now you should be able to visit your page in the CMS and select the poll from the new dropdown.

### Embed PollForm in your template

[](#embed-pollform-in-your-template)

Here's a suggestion how to create and expose a PollForm to all your templates:

```
class Page_Controller extends ContentController {
	...

	function PollForm() {
		$pollForm = new PollForm($this, 'PollForm', $this->Poll());
		// Customise some options
		$pollForm->setChartOption('height', 300);
		$pollForm->setChartOption('width', 300);
		$pollForm->setChartOption('colours', array('FF0000', '00FF00'));
		return $pollForm;
	}

	...
}
```

You will then be able to embed this form in your template like that:

```
$PollForm
```

This allows you to specify where you want the poll to show up. The poll will not appear if the related `SiteTree` object has no poll associated with it (i.e. $this-&gt;Poll() is empty).

### Customise the chart

[](#customise-the-chart)

You can obtain a good deal of control by redefining the **PollForm.ss** template in your **theme** folder. Here is the default setup:

```

	$Poll.Title

		$Poll.Image.ResizedImage(300,200)

		$Poll.Description

		$Chart

		$DefaultForm

```

And here is advanced setup that renders the poll as simple HTML blocks, using some of polls API functions:

```

			$Poll.Title

			$Poll.Description

						$Title $PercentageOfTotal ($Votes):
						&nbsp;

			$DefaultForm

		Total votes: $Poll.TotalVotes

```

If you want to make a site-wide changes, you can use a decorator and define **replaceChart** function. For example the following will give you a text-only rendering of results:

```
class PollFormDecorator extends DataObjectDecorator {
	function replaceChart() {
		$choices = $this->owner->Poll()->Choices('', '"Order" ASC');

		$results = array();
		if ($choices) foreach($choices as $choice) {
			$results[] = "{$choice->Title}: {$choice->Votes}";
		}

		return implode($results, '');
	}
}

Object::add_extension('PollForm', 'PollFormDecorator');
```

Finally, for a full control of the poll form and the results subclass the PollForm - you can then create form-specific templates or work on the basis of redefining the **getChart** method. This way you can also create multiple parallel presentation layers for the polls.

#### Custom Vote Handling

[](#custom-vote-handling)

Using the Vote\_Backend we can define our own vote handler. The votehandler takes care of storing votes and the logic of whether a user has voted before.

See `DatabaseVoteHandler` for an example.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance4

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/103bafe4fd658b6af5b4337efcf892c1255e10edbef796b424c4f32ce665483f?d=identicon)[mateusz](/maintainers/mateusz)

---

Top Contributors

[![mateusz](https://avatars.githubusercontent.com/u/118653?v=4)](https://github.com/mateusz "mateusz (37 commits)")[![tomspeak](https://avatars.githubusercontent.com/u/2415569?v=4)](https://github.com/tomspeak "tomspeak (10 commits)")[![phalkunz](https://avatars.githubusercontent.com/u/318116?v=4)](https://github.com/phalkunz "phalkunz (3 commits)")[![briceburg](https://avatars.githubusercontent.com/u/490144?v=4)](https://github.com/briceburg "briceburg (2 commits)")[![anselmdk](https://avatars.githubusercontent.com/u/1316533?v=4)](https://github.com/anselmdk "anselmdk (1 commits)")

### Embed Badge

![Health badge](/badges/mateusz-silverstripe-polls/health.svg)

```
[![Health](https://phpackages.com/badges/mateusz-silverstripe-polls/health.svg)](https://phpackages.com/packages/mateusz-silverstripe-polls)
```

###  Alternatives

[adigital/cookie-consent-banner

Add a configurable cookie consent banner to the website.

1150.7k](/packages/adigital-cookie-consent-banner)[michaels/data-manager

Simple data manager for nested data, dot notation array access, extendability, and container interoperability.

121.9k2](/packages/michaels-data-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
