Sponsors

We think outside the box... and solar system. Its true! We Promise ;) Just need a little... change??

Tutorial

Easy PHP Poll

Posted By: Aaron Heinen

Download the necessary files here

First thing to know is there are two poll.php files. The one on the root directory only controls the number of total polls to display. The one inside of the poll folder does not need to be changed.

Step 1) Open the poll/ folder

Step 2) Open the "config.php" file with Notepad++

Step 3) Scroll down until you see


// First poll definition

Step 4) These are the answers, there can be as many as you want, just make sure to change the number if you add any.



$p->question = " Change the Question here"

// Poll value ID and a display string
$p->add_value("1", "Highways");                                         

$p->add_value("2", "Driveways");

$p->add_value("3", "Parking Lots");

$p->add_value("4", "Bike Paths");

$p->add_value("5", "Sport Courts");

$p->add_value("6", "Playgrounds");

$p->add_value("7", "Military Use");

$p->add_value("8", "Underdeveloped Areas");

Step 5) This is important

If you are going to change the question / add a new poll, do not just change an existing one because the number of votes will still be saved from the old question.

If you make a new poll copy the entire script



$p = new Poll;

// Question displayed to the user
$p->question = "Which of the following applications of the Solar Roadway panels do
 you care most about?"; 

// Specify the URL to return to for this poll; may be relative or absolute
$p->returnToURL = "../poll.php";             
            
// Form legend; leave empty for none
$p->legend = "Solar Roadways Official Poll";  
                                      
// Control type; $CONTROL_RADIOBUTTONS or $CONTROL_COMBOBOX
$p->control_type = $CONTROL_RADIOBUTTONS;         

 // Poll value ID and a display string

$p->add_value("1", "Highways");                                        

$p->add_value("2", "Driveways");

$p->add_value("3", "Parking Lots");

$p->add_value("4", "Bike Paths");

$p->add_value("5", "Sport Courts");

$p->add_value("6", "Playgrounds");

$p->add_value("7", "Military Use");

$p->add_value("8", "Underdeveloped Areas");

$VALID_POLLS["1"] = $p;        

Now change the value of
$VALID_POLLS["1"] = $p;
to a number that you have not yet used, say 4 in this case.


$VALID_POLLS["4"] = $p;

Step 6)Now Go back to the poll.php file in the root directory, and edit it with Notepad++
Scroll down to find these lines of code



<?php
	require_once('poll/poll.php');
	show_vote_control('1');
?>
<p></p>
<hr />
<p></p>
<?php
	show_vote_control('2');
?>
<p></p>
<hr />
<p></p>

<?php      
	show_vote_control('3');
?>

This code shows all 3 polls, if you wanted to change the first poll to the new question you made, you would change:

show_vote_control('1');
to
show_vote_control('4');

poll.php and poll/config.php are the only two files that need to be edited to change the questions and answers of the poll.