SilverStripe - Using CheckboxsetField with MultiForm Module

I have a form using a multiform module. I have a checkboxsetfield populated with a given object.

I get strange results when saving the form. For example, if I select the first and third checkboxes, then this is how the array appears in the database: 1 {comma} 3 when I expected to see 1.3

MyDataObject.php

<?php
...
       if($SomeData = DataObject::get('SomeData')->sort('SortColumn'){
        $fields->push( new CheckboxSetField('SomeData', 'Field Name', $SomeData->map('ID', 'Name')
        ));
    }

      

MultiForm.php

<?php
...

public function finish($data, $form){

        if(isset($_SESSION['FormInfo']['MultiForm']['errors'])){
            unset($_SESSION['FormInfo']['Form']['errors']);
        }

        parent::finish($data, $form);

        $steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");

        $MyStep = $this->getSavedStepByClass('MyStep');

        if($this->getSavedStepByClass('MyStep')){
            if($MyStep->loadData()){
                $MyDataObject = new MyDataObject();
                $MyStep->saveInto($MyDataObject);
                $MyDataObject->write();
            }
        }
...

      

Any ideas on how to handle the array?

+3


source to share


1 answer


CheckboxSetField

has code that refers to {comma}

when saving to the database or when calling a function dataValue

. This essentially avoids any commas that were defined as values ​​in a row when stored in one column.

This tells me that either your multiform is not providing the correct input for CheckboxSetField

, or that there is more in this situation than your code shows.



If CheckboxSetField

gets an array like array('1,3')

, that is when I expect to see this type of result. Calling map

as if you were returning an object SS_Map

that cannot automatically convert what you expect. Try adding ->toArray()

after the call map

when you are passing values ​​to CheckboxSetField

.

If that doesn't solve the problem, we probably need to see ourselves DataObject

and a few other bits and pieces of information.

+1


source







All Articles