Checkbox group array values as comma separated string

m.pradel 03 Sep, 2013
Hi,

I have a form with an action, which directly post the form data into a Salesforce lead.

The Problem is, that the default output for a checkbox group is like that:

field_name1[]: value1
field_name1[]: value2

But to get the data right into Salesforce, I have to output the data of the checkbox group in this way:

field_name1[]: value1, value2

I've tried to use the handle_array action in the submit event, but nothing happened. Maybe the handle_array action only works togehter with a db_save or e_mail action on submit?!

Any Ideas how to solve this issue?

Regards,
Marc
GreyHead 03 Sep, 2013
Hi Marc,

The Handle Arrays action will convert
$form->data['field_name1'][]: value1
$form->data['field_name1'][]: value2 
into
$form->data['field_name1']: value1,value2 

Note: 1. The [] have gone - this may be your problem?

Note: 2. The order of the actions is important. You can add a Debugger action to see what data is present at any particular point in the processing sequence.

It may be more useful to you so use a Custom Code action to create a new variable:
<?php
$form->data['some_new_name'] = implode(',', $form->data['field_name1']);
?>

Bob
m.pradel 03 Sep, 2013
Hi Bob,

sorry for being inaccurate.

I need the field name without [], so it would be link you described:

$form->data['field_name1']: value1,value2

So, I've tried the custom code action on submit as controller, to put the values of the checkbox group into a hidden field. But it won't work.

I think this has to do with the order of the processed code. Because the form action calls a webservice from Salesforce the handle_array and the custom_code action on submit don't take effect.

Maybe it will be possible to grab the values directly when the user interact. Like the dynamic data method based on an ajax event?!

Regards,
Marc
GreyHead 05 Sep, 2013
Hi Marc,

How are you linking this form to SalesForce? If the form action points to SalesForce then ChronoForms will never see the submitted results and so can't do anything with them.

In that case you would need to use JavaScript in the form On Load event to build the value you need in a hidden input.

A better solution might be to use a CURL action in the On Submit event to send the data to SalesForce; then you can pre-process the results in ChronoForms. Please see this FAQ

Bob
m.pradel 06 Sep, 2013
Hi Bob,

thank you for the info.

I've used a little javascript to put the values into the hidden field

<script type="text/javascript">

    var $j = jQuery.noConflict();

    //<![CDATA[
    function checkArray(name) {

        $j('input[name=_'+name+'\\[\\]]').click(function() {
            var arr="";
            $j('input[name=_'+name+'\\[\\]]').each(function() {
                var thisCheck = $j(this);
                if (thisCheck.is(':checked'))
                    arr=arr+thisCheck.val()+",";
            });
            $j('input[name='+name+']').val(arr.substring(0, arr.length-1));
        });
    }

    $j(document).ready(function() {
        checkArray('hidden_field_name');
    });

    //]]> 


Regards,
marc
This topic is locked and no more replies can be posted.