PHP Poll Script

5 posts by 3 authors in: Forums > CMS Builder
Last Post: February 16, 2009   (RSS)

Hey,

I found a poll php poll script that works well on my site. I was trying to implicate the CMS to pull the question and options from but i keep getting syntax error.

here is the poll php script, how would i implement the viewer code?

<?php


require_once(dirname(__FILE__) . '/class.php'); // For the Poll class definition

// Modify this string to reflect the URL where DRBPoll is installed.
// A trailing slash must be included. This URL will be used in the generated
// HTML for the URL for the form submission. This may be a relative or
// absolute URL.
$POLL_URL = 'poll/';

// Names of the form input elements in the poll form.
// You probably won't need to change these unless the names conflict with some
// other element on your pages.
$POLL_ID_PARAM_NAME = "pollid";
$VOTE_PARAM_NAME = "vote";

// Maximum width of a bar of the poll results, in pixels
// Change this if you want to make the poll bar chart larger
// or smaller in width.
$MAX_POLL_BAR_WIDTH = 200;

// Whether or not the script should prevent the same IP address
// from voting multiple times on the same poll.
// Set to FALSE to allow duplicate votes.
$PREVENT_DUPLICATE_VOTES = TRUE;

// Whether or not vote counts should be displayed.
// If set to FALSE, only the percentages will be shown.
$SHOW_COUNTS = TRUE;

// These are the strings that are displayed in the poll control
// and the result page.
// Modify these to customize what is displayed to the user.
$SUBMIT_BUTTON_STRING = 'Submit';
$NUMBER_OF_VOTES_STRING = 'Total votes: %s';
$VOTE_STRING = 'Vote:'; // Used as label for combobox control type
$VOTE_LIST_DEFAULT_LABEL = 'Please Select'; // This is the "empty" option when using a combobox
$VIEW_RESULTS_STRING = 'Current Results';
$DUPLICATE_VOTE_ERROR_MSG = 'You have already voted!';
$NO_VOTE_SELECTED_ERROR_MSG = 'You forgot to select a value!';

// List of valid polls. All vote requests are checked against this list
// to ensure that malicious users do not submit invalid poll IDs through a
// cross-site request forgery.
//
// Add or modify the $VALID_POLLS array to add, modify, or remove polls.
// The key of the $VALID_POLLS associative array represents the poll ID;
// this value must be a string. In addition, it must only use alphanumeric
// characters (A-Z, a-z, and 0-9).
//
// Set the question property of the Poll object to a string representing
// the question to be displayed.
//
// Call add_value() on the Poll object to add a new value. The first
// parameter represents the value ID, which must be a alphanumeric string.
// The second parameter is the string to display to the user for this value.

$VALID_POLLS = array(); // The keys of this associative array are the poll IDs

// First poll definition
$p = new Poll;
$p->question = "What is your favorite color?"; // Question displayed to the user
$p->returnToURL = "../example.php"; // Specify the URL to return to for this poll; may be relative or absolute
$p->legend = ""; // Form legend; leave empty for none
$p->control_type = $CONTROL_RADIOBUTTONS; // Control type; $CONTROL_RADIOBUTTONS or $CONTROL_COMBOBOX
$p->add_value("1", "Red"); // Poll value ID and a display string
$p->add_value("2", "Green");
$p->add_value("3", "Blue");
$p->add_value("4", "Yellow");
$VALID_POLLS["1"] = $p; // "1" is the poll ID

// Second poll definition
$p = new Poll;
$p->question = "How old are you?"; // Question displayed to the user
$p->returnToURL = "../example.php"; // Specify the URL to return to for this poll; may be relative or absolute
$p->legend = "Second Poll"; // Form legend; leave empty for none
$p->control_type = $CONTROL_COMBOBOX; // Control type; $CONTROL_RADIOBUTTONS or $CONTROL_COMBOBOX
$p->add_value("1", "0-15 years"); // Poll value ID and a display string
$p->add_value("2", "16-20 years");
$p->add_value("3", "21-30 years");
$p->add_value("4", "31-40 years");
$p->add_value("5", "41-50 years");
$p->add_value("6", "50+ years");
$VALID_POLLS["2"] = $p; // "2" is the poll ID

?>

Re: [s2smedia] PHP Poll Script

heres the error i get:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/apexsocc/public_html/poll/config.php on line 80

poll is on this page:
http://www.apexsoccer.com/csk.php
(error message is in black so you'll have to highlight the text in the poll box to view it since it is a black BG)

heres the link to the config.php file containing viewer php code:
http://www.apexsoccer.com/poll/config.php

HERES THE CODE IN THAT FILE:

<?php

require_once "/home/apexsocc/public_html/cmsAdmin/lib/viewer_functions.php";

list($csk_pollRecords, $csk_pollMetaData) = getRecords(array(
'tableName' => 'csk_poll',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$csk_pollRecord = @$csk_pollRecords[0]; // get first record

?>
<?php


require_once(dirname(__FILE__) . '/class.php'); // For the Poll class definition

// Modify this string to reflect the URL where DRBPoll is installed.
// A trailing slash must be included. This URL will be used in the generated
// HTML for the URL for the form submission. This may be a relative or
// absolute URL.
$POLL_URL = 'poll/';

// Names of the form input elements in the poll form.
// You probably won't need to change these unless the names conflict with some
// other element on your pages.
$POLL_ID_PARAM_NAME = "pollid";
$VOTE_PARAM_NAME = "vote";

// Maximum width of a bar of the poll results, in pixels
// Change this if you want to make the poll bar chart larger
// or smaller in width.
$MAX_POLL_BAR_WIDTH = 200;

// Whether or not the script should prevent the same IP address
// from voting multiple times on the same poll.
// Set to FALSE to allow duplicate votes.
$PREVENT_DUPLICATE_VOTES = TRUE;

// Whether or not vote counts should be displayed.
// If set to FALSE, only the percentages will be shown.
$SHOW_COUNTS = TRUE;

// These are the strings that are displayed in the poll control
// and the result page.
// Modify these to customize what is displayed to the user.
$SUBMIT_BUTTON_STRING = 'Submit';
$NUMBER_OF_VOTES_STRING = 'Total votes: %s';
$VOTE_STRING = 'Vote:'; // Used as label for combobox control type
$VOTE_LIST_DEFAULT_LABEL = 'Please Select'; // This is the "empty" option when using a combobox
$VIEW_RESULTS_STRING = 'Current Results';
$DUPLICATE_VOTE_ERROR_MSG = 'You have already voted!';
$NO_VOTE_SELECTED_ERROR_MSG = 'You forgot to select a value!';

// List of valid polls. All vote requests are checked against this list
// to ensure that malicious users do not submit invalid poll IDs through a
// cross-site request forgery.
//
// Add or modify the $VALID_POLLS array to add, modify, or remove polls.
// The key of the $VALID_POLLS associative array represents the poll ID;
// this value must be a string. In addition, it must only use alphanumeric
// characters (A-Z, a-z, and 0-9).
//
// Set the question property of the Poll object to a string representing
// the question to be displayed.
//
// Call add_value() on the Poll object to add a new value. The first
// parameter represents the value ID, which must be a alphanumeric string.
// The second parameter is the string to display to the user for this value.

$VALID_POLLS = array(); // The keys of this associative array are the poll IDs

// First poll definition
$p = new Poll;
$p->question = "<?php echo $csk_pollRecord['title'] ?>"; // Question displayed to the user
$p->returnToURL = "../example.php"; // Specify the URL to return to for this poll; may be relative or absolute
$p->legend = ""; // Form legend; leave empty for none
$p->control_type = $CONTROL_RADIOBUTTONS; // Control type; $CONTROL_RADIOBUTTONS or $CONTROL_COMBOBOX
$p->add_value("1", "<?php echo $csk_pollRecord['opt1'] ?>"); // Poll value ID and a display string
$p->add_value("2", "<?php echo $csk_pollRecord['opt2'] ?>");
$p->add_value("3", "<?php echo $csk_pollRecord['opt3'] ?>");
$p->add_value("4", "<?php echo $csk_pollRecord['opt4'] ?>");
$VALID_POLLS["1"] = $p; // "1" is the poll ID

// Second poll definition
$p = new Poll;
$p->question = "How old are you?"; // Question displayed to the user
$p->returnToURL = "../example.php"; // Specify the URL to return to for this poll; may be relative or absolute
$p->legend = "Second Poll"; // Form legend; leave empty for none
$p->control_type = $CONTROL_COMBOBOX; // Control type; $CONTROL_RADIOBUTTONS or $CONTROL_COMBOBOX
$p->add_value("1", "0-15 years"); // Poll value ID and a display string
$p->add_value("2", "16-20 years");
$p->add_value("3", "21-30 years");
$p->add_value("4", "31-40 years");
$p->add_value("5", "41-50 years");
$p->add_value("6", "50+ years");
$VALID_POLLS["2"] = $p; // "2" is the poll ID

?>


thanks again!!

Re: [s2smedia] PHP Poll Script

By Dave - February 16, 2009

Hi s2smedia,

Anytime you get an error like this start with the line and file mentioned. In this case, line 80 in config.php which is:

$p->question = "<?php echo $csk_pollRecord['title'] ?>";

Since you are already inside a <?php block you don't need that again. Try replacing that with this:

$p->question = @$csk_pollRecord['title'];

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] PHP Poll Script

that'll do it!!

thanks!!