Jump to content

Social Impact Award - Voting Tool


Recommended Posts




Another nice little Showcase of what can quickly be done with Processwire :) I sponsored this voting tool for the Austrian Social Impact Award ceremony (https://socialimpactaward.net/) helping them to pick the winner of the audience voting.


The site is based on the default UIKIT theme (obviously) and i basically just placed the logo + changed the colors. The site structure is also very simple, having only one parent to store all teams, one parent to store all votes and one page to show the results (to the admins):


The Projects-Template stores some informations of the project and the vote-count:


All the votings are single pages as well having only one checkbox, ensuring that every code can only vote once (every visitor got one code at the entrance):


Votes are created via Tracy Console as easy as that:


The hook that creates the passwords is also simple:

 * create unique code for voting
$wire->addHookAfter('Pages::saveReady', function($event) {
  $page = $event->arguments(0);
  if($page->template != 'vote') return;

  if(!$page->title) {
    $rand = '';
    while(!$rand OR pages("title=$rand")->count() > 0) $rand = randomPassword();
    $page->title = $page->name = $rand;

And finally the check if the vote for this code is already done (inside the vote-template). the whole vote-template is as simple as that (thanks to the awesomeness of markup regions and functionsapi):

<?php namespace ProcessWire;
// handle votes (url segments)
if($id = $sanitizer->int($input->urlSegment1)) {

  // if voting is locked redirect to thankyou message
  if($page->votingdone) $session->redirect($page->url);

  // else set voting
  $team = pages($id);
  if($team->id) {
    // increase voting for this team
    $team->setAndSave('votes', $team->votes+1);

    // lock this votings page
    $page->setAndSave('votingdone', 1);

// if voting is done show thank you and lock page
if($page->votingdone): ?>
  <region id="main">
    <div class="uk-card uk-card-primary uk-card-body uk-width-1-1 uk-margin-small-top uk-text-center uk-border-rounded">
      <h3 class="uk-card-title">Danke für Ihre Teilnahme!</h3>
endif; ?>

<region id="main">

  <div class="uk-text-center uk-margin-top"><?= $page->parent->body ?></div>

  <?php foreach(pages('template=team, sort=random') as $team): ?>
    <div class="uk-card uk-card-default uk-card-body uk-width-1-1 uk-margin-small-top uk-border-rounded">
      <h3 class="uk-card-title uk-text-center"><?= $team->title ?></h3>

      <ul uk-accordion="collapsible: true">
          <p class="uk-accordion-title uk-text-center"><span uk-icon="icon: chevron-down"></span> Beschreibung anzeigen</p>
          <div class="uk-accordion-content">
            <?= $team->body ?>

      <a href="<?= $team->id ?>" class="uk-button uk-button-large uk-button-primary uk-width-1-1 uk-border-rounded">Für dieses Projekt abstimmen</a>
  <?php endforeach; ?>

I'm still impressed by ProcessWire and how much can be achieved with how little effort :)

  • Like 23
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...