1792 Posts in 588 Topics by 560 members
| Go to End | Next > | |
| Author | Topic: | 1390 Views |
-
Form to catch votes (poll like)

29 June 2011 at 3:57pm
Hello, I am trying to make a online image contest, but the users of the site have to vote for their favorite picture. I've created a page where the admin can upload the contestants and the people can see it in the front-end, but what I need to make is something like a poll but, per page, not in the entire site. My client says that mayber 3-4 polls can be taken at the same time.
Any ideas/suggestions/snippets for this???
Any help will be highly appreciated.
Thank You
-
Re: Form to catch votes (poll like)

30 June 2011 at 2:19am
Nice, I was looking that module yesterday but I can't figure how I can pass parameters to the function (I can create the poll with the same title of the page) and the $Title variable will be the parameter to select the specific poll for the page. I was trying to do something like
class Page_Controller extends ContentController {
...
function MyPoll($Title) {
return new ShowPoll($this, $Title);
}
...
}and, in the .ss I have to put $MyPoll($Title), but it doesn't seems to work, any suggestions??
-
Re: Form to catch votes (poll like)

30 June 2011 at 2:36am
When I get stuck with passing variable around I just use the session... bit hacky as it's like having global vaiables!
but Session::set('MyVar','something) and $myvar = Session::get('MyVar'); will get the job done
-
Re: Form to catch votes (poll like)

30 June 2011 at 3:00am
mmm nice solution... I have to put
Session::set('MyVar',$Title) and $myvar = Session::get('MyVar')
and then
class Page_Controller extends ContentController {
...
function MyPoll() {
return new ShowPoll($this, Myvar);
}
...
}and, in the .ss I have to put $MyPoll()
rigth?
-
Re: Form to catch votes (poll like)

30 June 2011 at 3:04am
hmmmm
I'd add a has_one Poll to the page so that in the cms the user can select the poll that is required on that page.
then in the init of the page I'd transfer the $this->PollID to the session
then in the poll display code I'd hack the bit that does a DataObject::get_one to get_by_id and use the value from the sessiondoes that make sense?
-
Re: Form to catch votes (poll like)

30 June 2011 at 3:53am
mmm makes sense... let me try it in a few hours and I'll let you know how is it going. BTW whe you say:
I'd add a has_one Poll to the page so that in the cms the user can select the poll that is required on that page.
Do you mean add a TextField or something where the user will enter the Poll ID? Is there any other to do it? Maybe generate a combo with all the active polls? (Too much complicated) or better I'll try with a TextField?
-
Re: Form to catch votes (poll like)

30 June 2011 at 4:03am Last edited: 30 June 2011 4:04am
I mean like this...
class MyPage extends Page {
...
static $has_one = array(
'Poll' => 'Poll'
);
...
function getCMSFields(){
$fields = parent::getCMSFields();
$dosPoll = DataObject::get('Poll');
$map = $dosPoll ? $dosPoll ->toDropdownMap('ID','PollTitle') : array();
$fields->addFieldToTab('Root.Content.Main', new DropdownField('PollID', 'Select a poll',$map));
return $fields;
}
...
}
| 1390 Views | ||
| Go to Top | Next > |


