Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Using the CheckboxsetField with MultiForm Module


Go to End


2 Posts   1077 Views

Avatar
Harley

Community Member, 165 Posts

28 April 2015 at 8:57am

Hi,

I have a form using the multiform module. I have a checkboxsetfield populated by a dataobject.

When saving the form I am getting strange results. For instance 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 how to process the array?

Cheers

Avatar
Harley

Community Member, 165 Posts

28 April 2015 at 10:33pm

I've just twigged that throughout the CheckboxSetField.php file the 'comma' is being replaced, it's just not honoured in the MultiForm module for some reason?

str_replace(",", "{comma}", $item);