• Resolved sicdesign

    (@sicdesign)


    I’m trying to integrate my registration form with Zoom in order to register a user for a webinar. I’m using Zapier and it does work… except that it will fail when I try to pass the address Country field data to Zoom. Zoom will only accept the 2 character ISO country code, not the name of the country. So to get around it I have to disable collecting the country field requirement in the Zoom webinar registration settings and then make sure to not pass the country field from my Forminator form to Zoom. Not ideal.

    So how can I pass the country code to Zoom instead of the name?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hi there @sicdesign

    I’ve escalated this question to our developers to see if there’s perhaps a filter that can be used for this.

    However, according to this little help doc at Zapier, the zap will fail regardless if the “country” field is set to “required” in the Zoom registration page, even if it’s populated in the Zap:
    https://zapier.com/help/doc/common-problems-zoom

    So it does look like you’d want to at least ensure that “country” is not set to required in Zoom.

    But let’s wait and see what our devs have to suggest ??

    Cheers!
    Patrick

    Thread Starter sicdesign

    (@sicdesign)

    Thanks for looking into this, Patrick.

    Yes, you are correct about the country code being required in Zoom. My work around was to still leave the Country registration question in Zoom as not required (for those who register on Zoom and not my form), and then in the Zap I simply don’t link the Zoom Country field at all. Later on I can export both Zoom and my form submissions as CSV files and then merge the data to find the accurate country data.

    If we can at some point get Forminator to output the 2 character country code then I can just go back to the Zap and link the country fields.

    Cheers!

    Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hi again @sicdesign

    Our devs came through with a couple of options for you that you can use in either your active theme’s functions.php file, or a mu-plugin (I always prefer mu-plugin for this kind of stuff as it’s theme independent). Both code options still display countries in full text on the front for users. ??

    This one changes the country label to the 2-character ISO code throughout for all forms, meaning the country would display as ISO in form submissions, and send as ISO to all integrations. Just need to be sure your address field ID is address-1 or change it in the code:

    add_filter( 'forminator_field_create_select', function ( $html, $attr ) {
    	$field_id = 'address-1';
    	if ( $attr['name'] === $field_id . '-country' ) {
    		$html = preg_replace_callback( '/<option value="(.*?)"\s*>(.*?)<\/option>/', function ( $matches ) {
    			preg_match( '/data-country-code="([^"]*)"/', $matches[0], $codes );
    			if ( isset( $matches[2] ) && isset( $codes[1] ) ) {
    				$matches[0] = sprintf( '<option value="%s" data-country-code="%s" >%s</option>', $codes[1], $codes[1], $matches[2] );
    			}
    			return $matches[0];
    		}, $html );
    	}
    	return $html;
    }, 10, 2 );

    This 2nd option is more granular as it can be used only for a specific form ID, and only changes how the country data is sent to Zapier. The country would still display in full in submissions, but Zapier would receive the ISO code that you can use with your Zoom zap there.

    Here again, change address-1 if needed to the correct field ID for your form (appears in 2 places in the code below), and change the 697 to the actual ID of your form:

    add_filter( 'forminator_addon_formatted_submitted_data', function( $formatted_post_data, $post_data, $files_data, $form_fields ) {
    	$form_id = filter_input( INPUT_POST, 'form_id', FILTER_VALIDATE_INT );
    	if ( 697 === $form_id && empty( $formatted_post_data['country_code'] ) && ! empty( $post_data['address-1-country'] ) ) {
    		$countries = forminator_get_countries_list();
    		$code      = array_search( $post_data['address-1-country'], $countries, true );
    		if ( $code ) {
    			$formatted_post_data['country_code'] = $code;
    		}
    	}
    	return $formatted_post_data;
    }, 10, 4 );

    Please do let us know if either of these work for you, or if you need more help with this.

    Cheers!
    Patrick

    Thread Starter sicdesign

    (@sicdesign)

    Wow! Thanks so much to you and the dev team for coming through with, not one, but two solutions! And super quick too!

    I will try this out soon and report back this weekend.

    Cheers!
    Andrew

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to save the 2 character Country Code not the country name?’ is closed to new replies.