Store multiple select-list values with Integrator - Crosstec
Welcome, Guest
Please Login or Register.    Lost Password?

Store multiple select-list values with Integrator
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: Store multiple select-list values with Integrator
#14135
Store multiple select-list values with Integrator 2 Months, 2 Weeks ago Karma: 0
Hello!

I am using Breezing Forms 1.7.1 for several days and I found it very impressive.
I like particularly the Integrator which is a very powerful feature.
The integrator works perfectly when saving elements that have a single record (example: username-joe doe)
Unfortunately, I encountered a problem when using the integrator for saving multiple-values generated by checkboxgroup or select-list with multiple option enabled in a joomla _jos table.
If I have a checkboxgroup with 3 values, and I check the all, for instance
0;apple;1
0;banana;2
0;mango;3
when I hit the submit button, only the last value (3, which corresponds to mango) is saved in the database _jos table, that is the last record for the fruit checkboxgroup element.
If I go to Manage records I can see all the 3 values are recorded in the breezing forms database, each one having a distinct record ID, but all of them the same element ID (I attached an example in the screenshot)

If I export to a csv file, I can see that the values are exported correctly. The checkboxgroup values are separated by comma, exactly as I need.
USERNAME;FRUIT;
Joe Doe;1,2,3;
But, when I check the _jos table in the phpmyadmin, I can see that only the last value is saved (3).

I also wrote a custom code in the code field from integrator to check if when submitting the form, the integrator saves all the 3 values or just one and I learned that it saves just the last value.
Here is the code:
function write($filePath,$what){
$df = @fopen ( $filePath, 'a+' );
if ( $df === false ) return false;
$line = "write(".date("H:i").")\n===============\n";
fwrite( $df, $line, strlen( $line ) );
$data = print_r ( $what, true );
fwrite($df, $data, strlen($data));
fwrite($df,"\n",strlen("\n"));
fclose( $df );
return true;
}
$filePath = "D:\logs.txt";

$result = write($filePath, $value);
if(!$result) {
throw new Exception("Nu pot deschide fisierul");
}

How can I make breezing forms save all the values (records) generated by checkboxgroup or select-list with multiple option enabled in a joomla _jos table?
Is this possible by writing a code in the integrator?
Or, maybe there is a different solution?

Thank you!
This image is hidden for guests. Please login or register to see it.
turumghita
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#14809
Re: Store multiple select-list values with Integrator 1 Month, 2 Weeks ago Karma: 0
Any solution to this?
molly
Fresh Boarder
Posts: 16
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#14966
Re: Store multiple select-list values with Integrator 1 Month, 1 Week ago Karma: 0
I didn't find any solution so far, unfortunately.
turumghita
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#15411
Re: Store multiple select-list values with Integrator 1 Month ago Karma: 0
I had the same problem with multi-select elements in the integrator but, after an hour or so, managed to come up with a solution, so thought I'd share ...

You'll have to edit the following file -
/administrator/components/com_breezingforms/libraries/crosstec/classes/BFIntegrate.php

Find the following:
Code:


public function field(array $data){
$this->data['data'.$data[_FF_DATA_ID]] = $data;
$i = 0;
foreach($this->rules As $rule){
$items = $this->getItems($rule['rule']->id);
$j = 0;
foreach($items As $item){
if($item->element_id == $data[_FF_DATA_ID]){
$this->rules[$i]['items'][$j]['item'] = $item;
$this->rules[$i]['items'][$j]['data'] = $data;
}
$j++;
}
$i++;
}
}



and change to:
Code:


public function field(array $data){
// check to see if element has already been processed
if(isset($this->data['data'.$data[_FF_DATA_ID]])) {
// if this is the first duplicate then create array
if(!isset($this->data_arrays)) $this->data_arrays = array();
// if this is the first duplicate of this element then make sure we've added an array keyed by element id 
// and fill with first value found from the last pass
if(!isset($this->data_arrays[$data[_FF_DATA_ID]])) $this->data_arrays[$data[_FF_DATA_ID]][] = $this->data['data'.$data[_FF_DATA_ID]][_FF_DATA_VALUE];
// add current element value
$this->data_arrays[$data[_FF_DATA_ID]][] = $data[_FF_DATA_VALUE];
}
$this->data['data'.$data[_FF_DATA_ID]] = $data;
$i = 0;
foreach($this->rules As $rule){
$items = $this->getItems($rule['rule']->id);
$j = 0;
foreach($items As $item){

if($item->element_id == $data[_FF_DATA_ID]){
$this->rules[$i]['items'][$j]['item'] = $item;
// copy $data var so we don't change it
$tempdata = $data;
// if this element has been added as an array then use that as value
if(array_key_exists($item->element_id,$this->data_arrays)) $tempdata[_FF_DATA_VALUE] = $this->data_arrays[$item->element_id];
$this->rules[$i]['items'][$j]['data'] = $tempdata;
}
$j++;
}
$i++;
}
}



I've added comments which hopefully explain what's going on, although it's now almost 2am and I can barely see straight so it might not make much sense!
I suspect there might be a better way of doing this, although this seems to work and only requires one function change. Haven't done much testing though.

After making this code change, the '$value' variable in the integrator will turn into an array of values for multi-select elements.
Just use something like
Code:

if(is_array($value)) $value = implode(',',$value);
in the integrator code to add a comma separated list of values to your db.

Note: this won't affect form update criteria data, so don't use multi-selects for that.

Hope this helps,
Steve
angelcoding
Fresh Boarder
Posts: 1
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2010/08/08 04:03 By angelcoding.Reason: Integrator code didn't take into account single values - does now
The administrator has disabled public write access.
 
#15450
Re: Store multiple select-list values with Integrator 1 Month ago Karma: 0
Hello Steve!

Thanks for sharing your solution with us.
I applied your code changes and it is now possible to save multiple values using integrator.
You're a really coding angel.
Thanks once again!
turumghita
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 1
Moderators: TheMuffinMan