Page 1 of 1

[solved] Form Builder to ListIt2 - multi-option fields

Posted: Wed Apr 09, 2014 5:36 am
by Cerulean
When sending Form Builder submissions to ListIt2 as per the great tutorial here , I'm striking a problem with multi-option fields such as Multi Select and Check Box Group.

I have identical fields and options set up in both Form Builder and ListIt2. The UDT does seem to be copying over the values from Form Builder to ListIt2 but when I view the record in the ListIt2 admin the selected options are not shown as selected.

I created a record via the ListIt2 admin for comparison and had a look at an SQL dump. When a record is created via ListIt2 the selected options for a Multi Select or Check Box Group are saved to the database like...

Code: Select all

(1,5,0,'Option One',NULL),(1,5,1,'Option Two',NULL),(1,5,2,'Option Three',NULL)
But when the record comes from Form Builder via the UDT the options are saved to the database like...

Code: Select all

(1,5,0,'Option One,Option Two,Option Three',NULL)
Any suggestions on how I can get Multi Select and Check Box Group fields from Form Builder to ListIt2 in such a way so that the selected options are displayed and are editable in the ListIt2 admin?

Re: Form Builder to ListIt2 - problem with multi-option fiel

Posted: Wed Apr 09, 2014 8:58 am
by Stikki
$fb_result = explode(',', $params['multiselect_field_from_fb']);

$item->field_alias = $fb_result;

$mod->SaveItem($item);

Re: Form Builder to ListIt2 - problem with multi-option fiel

Posted: Thu Apr 10, 2014 2:00 am
by Cerulean
Beautiful, thanks.

Putting it together with the original UDT...

Code: Select all

// Load wanted ListItExtended instance, where you want to save items. If instance can't be loaded it will silently return.
$mod = cmsms()->GetModuleInstance("ListIt2MyInstance");
if(!is_object($mod)){
	return;
}

// Intitate empty item using API.
$obj = $mod->InitiateItem();

// Fill previously initiated ListIt2Item object with values from form submission.
// All params that are not known by ListIt2Item object are going to ignored.   
$obj->title = $params["MyRequiredField"];
foreach($params as $key => $value) {
	if(isset($obj->fielddefs[$key])){
		if($key == "MyMultioptionAlias"){
			$multi_result = explode(",", $params["MyMultioptionAlias"]);
			$obj->MyMultioptionAlias = $multi_result;
		} else {
			$obj->$key = $value;
		}
	}
}

// Save this object to database by using ListItExtended API.    
$mod->SaveItem($obj);