Jump to:

1970 Posts in 1272 Topics by 607 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: 1639 Views
  • gvelasquez85
    Avatar
    Community Member
    11 Posts

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

    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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts
  • gvelasquez85
    Avatar
    Community Member
    11 Posts

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

    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??

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

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

    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

  • gvelasquez85
    Avatar
    Community Member
    11 Posts

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

    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?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

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

    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 session

    does that make sense?

  • gvelasquez85
    Avatar
    Community Member
    11 Posts

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

    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?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

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

    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;
       }
    ...   
    }

    1639 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.