1779 Posts in 582 Topics by 556 members
| Go to End | ||
| Author | Topic: | 1353 Views |
-
Re: Form to catch votes (poll like)

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.
-
Re: Form to catch votes (poll like)

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?
-
Re: Form to catch votes (poll like)

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)
-
Re: Form to catch votes (poll like)

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!
| 1353 Views | ||
| Go to Top |


