Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Checking checkboxes in a templated form

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

Page: 1
Go to End
Author Topic: 530 Views
  • NETim
    Community Member
    24 Posts

    Checking checkboxes in a templated form Link to this post


    Working on a site that has a search filter bar with checkboxes.

    Try as i might i haven't been able to check the selected checkboxes when the page loads.

    The basic idea is that a search page can be set to pre-select certain items (not all). The page will also check any checkboxes chosen by the user when the form reloads.

    Any suggestions of how to do this?



  • Willr
    Forum Moderator
    5508 Posts

    Re: Checking checkboxes in a templated form Link to this post

    If you're using a CheckboxSetField you should be able to call setValue() on the field and pass in your array of defaults. As long as the keys match, they will be selected by default

    $field = new CheckboxSetField('Field', 'Title', array('Option1' => 'Foo', 'Option2' => 'Bar'));
    $field->setValue(array('Foo' => true));

Page: 1
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.