Only first value in array for checkbox group in DB loader

JeLu 22 May, 2014
Hi!

I have a form that ckecks if the record exist or if it is a new record. If it exist it loads another form with values from the record. For this I use DB Record Loader in the second form.

My problem is that the group for checkboxes only fills in the first value.

The array looks like this:
[check2] => Array
        (
            [0] => B1
            [1] =>  B2
            [2] =>  B3
        )

Value [0] there is no space but in the other there is. B1 is checked but B2 and B3 is unchecked.

I found a similar problem in the forum and tried to explode the array but that did not help. Also I have tried to add a space in "Array separator" in advanced settings for DB Loader.

Any idee?

//JeLu
GreyHead 27 May, 2014
Hi JeLu,

How is the data saved in the database? What do you see if you add a Debugger to the form?

Bob
JeLu 09 Jun, 2014
In the record the checkbox-group is stored like B1, B2, B3 and debugger info about array is like this

[check2] => Array
         (
             [0] => B1
             [1] =>  B2
             [2] =>  B3
         )


As you see it is a space before value [1] and value [2] but not in front of value [0].

The data I have to pick up is from an old form running ChronoForm 3 and joomla 1.5.

I need the values but in CF 4 and Joomla 3

it is about 10 000 records and I hope not to delete spaces in every checkbox-group for all that records.

//JeLu
GreyHead 09 Jun, 2014
Hi JeLu,

On the Advanced tab in the DB MultiRecord Loader action is an Array Separators box, please try setting that to ', ' that is comma followed by a space.

Bob
JeLu 10 Jun, 2014
Hi!

I have tried that but it did not work. I noticed that any new record I create with my CF4 form are saved without spaces and those records are shown as they should.

But I need to access all the old records too 🙄

//JeLu
JeLu 10 Jun, 2014
[check1] => Array
        (
            [0] => A2
            [1] =>  A3
            [2] =>  A4


This is what debugger says about Checkboxgroup check1
[attachment=0]check1.jpg[/attachment]
JeLu 10 Jun, 2014
Can I strip the array when load a record for edit. There is no problem with a value in the records without spaces. I only need it to pick them up for old records too.

//JeLu
GreyHead 10 Jun, 2014
Answer
Hi Jelu,

In a Custom Code action you can try this
<?php
if ( is_array($form->data['check1']) && count($form->data['check1']) > 1 ( {
  foreach ($form->data['check1'] as $k => $v ) {
    $form->data['check1'][$k] = trim($v);
  }
}
?>

Or you can use PHPMyAdmin and update the records with something like this (backup the database table first for safety):
UPDATE `table_name` 
  SET `check1` = REPLACE(`check1`, ', ', ',');

Bob
JeLu 10 Jun, 2014
Run update like you suggested in phpAdmin and it seems to have removed every whitespace in my arrays.

So now am I happy, until next problem 😉

Thank You Greyhead!!!
This topic is locked and no more replies can be posted.