Jump to:

1976 Posts in 1306 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » Neater way of template for CheckboxSetField form item

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

Page: 1
Go to End
Author Topic: 1093 Views
  • MarijnKampf
    Avatar
    Community Member
    161 Posts

    Neater way of template for CheckboxSetField form item Link to this post

    I'm now using the following code to display the selected checkboxes from a CheckboxSetField in a form:

    MyForm.php

    new CheckboxSetField(
       $name = "MyCheckboxes",
       $title = "Title",
       $source = array(
          "Option1" => "Option 1",
          "Option2" => "Option 2",
       )
    )

    MyForm.ss

    <% control MyCheckboxes %>
       <% if Option1 %><li>One</li><% end_if %>
       <% if Option2 %><li>Two</li><% end_if %>
    <% end_control %>

    Is there an easier/better way of only including the selected checkboxes in my form? As the above works well with a small number of options, but quickly adds a lot of code for longer option lists.

    1093 Views
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.