Posted by christian
2016-01-19

Tom,
First off; many thanks!!!! This script really helped me further my knowledge of php. (which was extremely minimal/sad...now just kinda sad) :)

So here's my question(s): I want to add a description underneath each item in the poll. I've tried this a couple of different ways and I *think* this is the closest to correct but I can't quite get it to work for me. I'm going to cut some of the code/choices out just for readability.

/* [from 'class.inc.php' */
//-- Poll Title
$poll ->attr("title", "Who's your favorite fictional character?");

/* each item in the list get's a description attr */
//--Poll Options
$poll->addItem("Bart Simpson");
//-- Poll Attribute
$poll->attr("description", "El Barto);

//-- method/question 2: How to add html elements to the template without going to the database. to the pollItem. Something like...
$poll->addItem("Leopold Butters Stotch:<br><div id='sub-text'><I>A.K.A Professor Chaos</I></div>");

/* The "Butters example" is kind of what I ran into when trying to hack my way into adding in-line style to $items in the $item array (stored in data.txt).*/

/*[from 'tpl.front.inc.php]*/
/* [from tpl.reult.inc.php' */
//-- I know lns 16 - 55 and the foreach is the key
<!-- [BEGIN] Looping through all the items -->
<div style='margin:20px 0 30px 0'>
<table class='poll-table' border="0" cellpadding="0" cellspacing="0" width='100%'>
<?php foreach( $poll->getAllItems() as $item ) { ?>
<tr>
<td class='ap-container' align='left'>
<div class='poll-item'>
<label style='cursor:pointer;'>
<input type="<?php echo $poll->attr( "vote-input" ); ?>"
name="answer"
value="<?php echo $item->getName(); ?>" />
<?php echo $item->getName(); ?>
</label>
</div>
</td>
</tr>
<!-- maybe a switch case here would help ? But ultimately I want to display a different description on both the front and results page of poll-simple-->
<tr>
<td></td>
</tr>
<?php } ?>
</table>
</div>
<!-- [END] Looping through all the items -->

Any help would be GREATLY appreciated as I'm really stumped :\
Thank you again,
-Christian
Posted by Tom
2016-01-20

Hi,

>I want to add a description underneath each item in the poll.

Find lines like this in class.inc.php
$poll->addItem( "Chrome" );
$poll->addItem( "Internet Explorer" );
$poll->addItem( "Safari" );
Use $item->attr to set "description" like this:
$item = $poll->addItem( "Chrome" );
$item->attr("description","A web browser developed by Google");
$item = $poll->addItem( "Internet Explorer" );
$item->attr("description","A web browser developed by Microsoft");
$item = $poll->addItem( "Safari" );
$item->attr("description","A web browser developed by Apple");
You can display description with this PHP tag
<?php echo $item->attr("description"); ?>
If you want to have two different texts for the front and the result page,
then do this:
$item = $poll->addItem( "Chrome" );
$item->attr("description-front","A web browser developed by Google");
$item->attr("description-result","Google Chrome has a 58% worldwide usage share of web browsers as a desktop browser");
To display description-front in the front template, use
<?php echo $item->attr("description-front"); ?>
To display description-result in the result template, use
<?php echo $item->attr("description-result"); ?>