Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Form to catch votes (poll like)


Go to End


12 Posts   3559 Views

Avatar
gvelasquez85

Community Member, 11 Posts

30 June 2011 at 4:26am

I was thinking in the same.. (but I'm not as fast as you in SS). Let me try and I'll tell you.

Thank You.

Avatar
gvelasquez85

Community Member, 11 Posts

30 June 2011 at 3:54pm

Hello, good news pal..., I've set something 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;
}
...
}

and in the controller

class GuerraPage_Controller extends Page_Controller {
function MyPoll() {
Session::set('MyVar',$this->Title);
$myvar = Session::get('MyVar');
return new ShowPoll($this, $myvar);
}

and it works automatically. The only thing that you have to do is to set the title of the poll IDENTICALLY to the title of the page.

Now I'm facing a problem (how to use the poll module, where to redirect the visitor after the vote, where to show the votes). Any info here?

Avatar
swaiba

Forum Moderator, 1899 Posts

1 July 2011 at 4:13am

hmmmmm

$myvar = Session::get('MyVar'); 
return new ShowPoll($this, $myvar);

I was suggesting that you use the session to pass the id of the required poll into the polls module...
So the code in the page init would be...

function init() {
parent::init();
Session::set('PollID',$this->PollID); 
}

and then using that in the polls module

function __construct($controller, $name,$iPollID) 
... 
$poll = DataObject::get_by_id('Poll', Session::get('MyPollID'));

and then your page template would only need...

$ShowPoll;

(al untested)

Avatar
gvelasquez85

Community Member, 11 Posts

1 July 2011 at 4:12pm

It works, but now, how can I get the poll to work?. I mean, I show the poll in the page, but, when I vote, the system get me to a page that doesn't exists. How can I manage that?. I can see a discusion link option, do you know how to use it?. How can I redirect the poll to the same page when the people votes?.

Thank You!

Go to Top