Change the checklist value separator from comma to pipe when sending to ZohoCRM [RESOLVED]

I am trying to use the checkbox on my sign up form to allow users to pick between 4 options. After the options are selected, pass the results to our ZohoCRM and map it to a multi-line field (originally, I want to map it to a pick list but this is not supported by gravity form, which is a shame and my only choice is the multi-line field).

Once the data goes into my multi-line field, it looks like this:

["Option1","Option2","Option3"]

Unfortunately, ZohoCRM doesn’t like this format and it causes issue with all of our workflows and blueprint.

I need gravity form to replace the comma separator with a pipe so that it looks like this:

["Option1"|"Option2"|"Option3"]

I tried the steps on this page & replace activecampaign with zohocrm:

Added it to my functions.php:

add_filter( 'gform_zohocrm_field_value', 'gf_replace_commas_with_pipes', 10, 4 );
function gf_replace_commas_with_pipes( $value, $form, $entry, $field_id ) {
    $field = GFAPI::get_field( $form, $field_id );
 
    if ( is_object( $field ) && ( $field->type == 'checkbox' || $field->type == 'multiselect' ) ) {
        $value = str_replace( ', ', '||', $value );
    }
    return $value;

But when the data reaches zohocrm, it’s still a comma: https://jmp.sh/mWLV0Jb

The comma is causing issues with my zohocrm workflow and I need the separator in pipe instead.

Thanks!

Hello Sai. I recommend adding some logging statements to your code:

I would add a logging statement for every object and variable, any time you are setting it or trying to use it, to see what is contains. You may even find that your function is not being called at all for some reason. Once you have added the logging statements to your code, be sure you enable logging for Gravity Forms:

Let us see the new code (with the logging statements) and the link to the Gravity Forms Core log after you’ve tested the code with the logging statements added. Thank you.

Here’s the new code with logging statements:

        /* Replace Commas with Pipes */
    add_filter( 'gform_zohocrm_field_value', 'gf_replace_commas_with_pipes', 10, 4 );
    function gf_replace_commas_with_pipes( $value, $form, $entry, $field_id ) {
        $field = GFAPI::get_field( $form, $field_id );
     
        if ( is_object( $field ) && ( $field->type == 'checkbox' || $field->type == 'multiselect' ) ) {
            $value = str_replace( ', ', '||', $value );
        }
    	
    	GFCommon::log_debug( "log_save_field_value: Input ID: {$input_id}. POST value => " . print_r( rgpost( $input_name ), true ) );
        GFCommon::log_debug( 'log_save_field_value: Saved value => ' . print_r( $value, true ) );
    	
        return $value;
    }

Here’s the log:

I added a few more logging statements. Can you please try this, then send a link to the log file?

/* Replace Commas with Pipes */
add_filter( 'gform_zohocrm_field_value', 'gf_replace_commas_with_pipes', 10, 4 );
function gf_replace_commas_with_pipes( $value, $form, $entry, $field_id ) {
	GFCommon::log_debug( __METHOD__ . '(): FORM => ' . print_r( $form, true ) );
	GFCommon::log_debug( __METHOD__ . '(): ENTRY => ' . print_r( $entry, true ) );
	GFCommon::log_debug( __METHOD__ . '(): FIELD ID => ' . print_r( $field_id, true ) );
	GFCommon::log_debug( __METHOD__ . '(): VALUE => ' . print_r( $value, true ) );
	
	$field = GFAPI::get_field( $form, $field_id );
	
	GFCommon::log_debug( __METHOD__ . '(): FIELD => ' . print_r( $field, true ) );
	if ( is_object( $field ) && ( $field->type == 'checkbox' || $field->type == 'multiselect' ) ) {
		GFCommon::log_debug( __METHOD__ . '(): Matched field type.' );
		GFCommon::log_debug( __METHOD__ . '(): VALUE BEFORE => ' . print_r( $value, true ) );
		$value = str_replace( ', ', '||', $value );
		GFCommon::log_debug( __METHOD__ . '(): VALUE AFTER => ' . print_r( $value, true ) );
	}
	// this log line won't do anything, because $input_id is not defined anywhere
	GFCommon::log_debug( "log_save_field_value: Input ID: {$input_id}. POST value => " . print_r( rgpost( $input_name ), true ) );
	GFCommon::log_debug( 'log_save_field_value: Saved value => ' . print_r( $value, true ) );

	return $value;
}

Thanks Chris,

Here’s the core log: https://www.currentware.com/wp-admin/admin.php?page=gf_settings&subview=gravityformslogging

Here’s the zoho crm add-on log: https://www.currentware.com/wp-content/uploads/gravity_forms/logs/gravityformszohocrm_d119c15943e5541cbbaafb5ff74f46b7eaf62ca8.txt

Chris,
Instead of mapping it to a multi-line field, we used the multi-select field instead and it works for us without changing the separator. Thanks for you help. You can close this.

1 Like