Jump to:

23553 Posts in 19380 Topics by 2892 members

General Questions

SilverStripe Forums » General Questions » Pass CheckboxSetField array to DropdownField?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1420 Views
  • AlaVive
    Community Member
    42 Posts

    Pass CheckboxSetField array to DropdownField? Link to this post

    I always feel like I'm posting to the wrong place on the forums, but I'm taking a stab at this again.

    I'm using a CheckboxSetField to add multiple brand names to each PDF that's uploaded to a technical documents section of the site.

    I need to be able to search the different PDF files using "Brands" as a field, but I wan to be able to pass the array of options to a dropdown, rather than a text search.

    Using ComplexSearch, is there a way to pass the array from the CheckboxSetField to a dropdown?


    class TechDoc extends DataObject
       static $db = array (
          'Name' => 'Text',
          'Brand' => 'Varchar',
          'Description' => 'Text',
          'Language' => "Enum('English, French, Spanish, Portuguese, Polish, German')"
       static $has_one = array (
          'Attachment' => 'File',
          'TechDocPage' => 'TechDocPage'
       static $has_many = array(
          'TechDoc' => 'Brand'


       public function getCMSFields_forPopup()
          return new FieldSet(
             new TextField('Name'),
             new TextareaField('Description'),
             new CheckboxSetField('Brand','Brand',(array ("BrandA" => "BrandA","BrandB" => "BrandB","BrandC" => "BrandC"))),
             new DropdownField('Language','Language', singleton('TechDoc')->dbObject('Language')->enumValues()),
             new FileIFrameField('Attachment')
       static $searchable_fields = array(
             'Name' => 'PartialMatchFilter',
             'Language' => 'ExactMatchFilter',
             'Description' => 'PartialMatchFilter',
       /*This does work, but I need a dropdown*/
          'Brand' => 'PartialMatchFilter'
             /*This does not work, since I can't pass it the array for the dropdown:
          'Brand' => array(
              'title' => 'Brand',
              'field' => 'DropdownField',
              'filter' => 'PartialMatchFilter'
       public function getCustomSearchContext() {
          $fields = $this->scaffoldSearchFields(array(
             'restrictFields' => array(
          /*This seems redundant, but I'm working from the tutorial...*/
          $filters = array(
             'Name' => new PartialMatchFilter('Name'),
             'Brand' => new PartialMatchFilter('Brand'),
             'Language' => new ExactMatchFilter('Language'),
             'Type' => new PartialMatchFilter('Type')
          return new SearchContext(


    If there's a better way to do this, I'm perfectly happy to know how I might change this ;-).

    Thanks in advance.

  • AlaVive
    Community Member
    42 Posts

    Re: Pass CheckboxSetField array to DropdownField? Link to this post

    I'm sure there's probably a better way to ask this-- that's part of my problem.

    But, even if I find out what I need to do is impossible, it would save me some time and a boat-load of stress.


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.