Checkbox group

francescocartei 03 Sep, 2016
Hi,
In a first page I have a form with a checkbox group, his field name is 'color[]' and there are three options: blue, red, green.
In a second page there is a custom code with {color}
My output is: array ( 0 => 'blue', 1 => 'green', )
Instead I would have as output simply blue,green
How can i do?
francescocartei 04 Sep, 2016
I don't understand where I need to put this code...
In a custom code?
<?php
$color_array = array(
  1 => 'green',
  2 => 'blue',
  3 => 'red',
  4 => 'white'
);
$color_names = array();
foreach ( $form->data['colors'] as $v ) {
  $color_names[] = $color_array[$v];
}
$form->data['color_names'] = implode(', ', $color_names);
?>
GreyHead 04 Sep, 2016
Hi amandocurcio,

If you need to use it then it would go in a Custom Code action in the form On Submit event. But it might be simpler to just change the options list in the drop-down element.
green=green
blue=blue
red=red
white=white

Bob
francescocartei 04 Sep, 2016
Perhaps I do not explain well🙂
On the first page I have a checkbox group ( field name: 'colors[]', options: green = green blue = blue red = red white = white )
On the second page I have a custom code with code {colors}.
When on the first page I choose the colors white and blue, the second page I have this string : array ( 0 = > ' blue ' , 1 = > ' white ' , ), instead I need to display: blue, white
How can I do?🙂
GreyHead 04 Sep, 2016
Hi armandocurcio

Please drag a Handle Arrays action into the OnSubmit event and move it up before the Email action. See the end of the FAQ.

Bob
GreyHead 04 Sep, 2016
Answer
Hi armandocurcio,

Your image is so big that it is impossible to read easily here.

If you are using the green=green options list then you do not need the Custom Code at all, At present it may well over-write the submitted values.

The Custom element in Page 2 is before the Handle Arrays action (which is in the On Submit event and so is only run after Page 2 submits). That is why you still see the array in Page 2.

Adding Debugger actions temporarily will give you a clearer view of what is happening.

Bob
This topic is locked and no more replies can be posted.