Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Form to catch votes (poll like)

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

Page: 1 2
Go to End
Author Topic: 1807 Views
  • gvelasquez85
    Avatar
    Community Member
    11 Posts

    Re: Form to catch votes (poll like) Link to this post

    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.

  • gvelasquez85
    Avatar
    Community Member
    11 Posts

    Re: Form to catch votes (poll like) Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Form to catch votes (poll like) Link to this post

    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)

  • gvelasquez85
    Avatar
    Community Member
    11 Posts

    Re: Form to catch votes (poll like) Link to this post

    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!

    1807 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.