Welcome, Guest

Store multiple select-list values with Integrator
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Store multiple select-list values with Integrator

Store multiple select-list values with Integrator 1 year, 11 months ago #14135

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!
manage_records.png
  • turumghita
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0

Re: Store multiple select-list values with Integrator 1 year, 10 months ago #14809

Any solution to this?
  • molly
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Karma: 0

Re: Store multiple select-list values with Integrator 1 year, 10 months ago #14966

I didn't find any solution so far, unfortunately.
  • turumghita
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0

Re: Store multiple select-list values with Integrator 1 year, 9 months ago #15411

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:
	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:
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
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
Last Edit: 1 year, 9 months ago by angelcoding. Reason: Integrator code didn't take into account single values - does now

Re: Store multiple select-list values with Integrator 1 year, 9 months ago #15450

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
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0

Re: Store multiple select-list values with Integrator 1 year, 2 months ago #31325

Thanks.
  • aderse02
  • OFFLINE
  • Junior Boarder
  • Posts: 26
  • Karma: 0
Last Edit: 2 months ago by aderse02.
  • Page:
  • 1
  • 2
Moderators: TheMuffinMan, ForumSupport
Time to create page: 0.43 seconds

Facebook Discount - 40% Off!

Fans of our Facebook page here are entitled to get a 1-year-subscription for the price of a 6-months!

Steps to take:

  • Become a fan on Facebook (Like) here
  • Purchase a 6-months-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of your like and we'll upgrade to the 1-year-subscription

Joomla!® Forms Discount - 40% Off!

Already purchased a forms extension from a different vendor but your requirements changed and now you need a forms extension that is capable of more than just the standards? We help you to keep the costs for a change under control: Get a 40% discount on our professional membership plan! -- meaning timely unlimited access to all current and future commercial extensions, breezingforms themes & apps and Joomla!® templates at crosstec.de, including 1 year of support -- without any website limitations -- Just prove that you previously purchased another forms extension for Joomla!® from a different vendor and you are qualified.

Steps to take:

  • Purchase a 1-year-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of the purchase for the other form vendor and we'll upgrade to the professional-subscription

About

Crosstec GmbH & Co. KG

Bergisch-Gladbacher-Str. 829

51069 Cologne, Germany

Imprint