Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Gravity Forms - Constant Contact Post problem #8

Closed
dmd33 opened this Issue · 11 comments

2 participants

@dmd33

Hi, I posted this over on the Wordpress support forms today:

I am running into an issue with this plugin. I am trying to pass several mailing list names from Gravity Forms to Constant contact. Constant contact requires them to be submitted like this:

http://yourdomain.com/CCSFG_x.x.x/signup.php?EmailAddress=jsmith@yourdomain.com&Lists=ListName

If you are using multiple lists it should look like this &Lists[]=List1&Lists[]=List2&Lists[]=List3

This plugin is passing the list selection along like this: &Lists[]=List1,List2,List3 Is there a way to force the plugin to use the entire field name each time?

second post:

I tried two workarounds without success: I changed the separator to &Lists[]= but it didnt work. Then I removed the separator entirely and set two of the field values in Gravity Forms to &Lists[]=ListName1 and &Lists[]=ListName2 and that didn't work.

Using both of these methods fields post like this:

[FirstName] => NAME1
[LastName] => NAME2
[EmailAddress] => EMAIL@DOMAIN.COM
[CountryCode] => US
[City] => CITY
[StateCode] => AL
[PostalCode] => 99999
[Lists[]] => LIST1&Lists[]=LIST2&Lists[]=LIST3

Is there any way to separate the last line into three separate [Lists[]} => lines?

@zaus
Owner

hm...i'm looking into it, and it's a little complicated to format correctly (see similar issue, example). i'll see what i can come up with, but in the meantime you could use the ...service_filter_post hook as a place to split up the list and replace the post string.

Something like:

function forms3rdparty_list_fix($post, $service, $form, $sid) {
    // what to replace
    $field = 'List';
    $list = $post[$field];
    //remove so it doesn't get urlified
    unset($post[$field]);
    // turn into querystring so you can append formatted list
    $post = http_build_query($post);
    // append list in correct format
    $post .= $field . '[]=' . implode('&' . $field . '[]=', explode($service['separator'], $list));
    // expose back to submission
    return $post; 
}
add_filter('Forms3rdPartyIntegration_service_filter_post', 'forms3rdparty_list_fix', 10, 4);
@dmd33

I will look into this, it might be a little beyond my capabilities though.

@dmd33

Hi, it doesn't seem to be working. The POST is very screwy looking now.

[timeout] => 10
[body] => FirstName=NAME&LastName=NAME&EmailAddress=NAME2%40DOMAIN.COm&CountryCode=COUNTRY&City=CITY+CITY&StateCode=STATE&PostalCode=ZIP&Lists%5B%5D%5B%5D=LIST1&Lists%5B%5D%5B%5D=LIST2l&Lists%5B%5D%5B%5D=LIST3

@zaus
Owner

That should be fine -- it's url-encoded. What does it look like coming from the service response?

@zaus
Owner

In fact, if you test it using the service debug you should see the array come back as expected.

@dmd33

Thanks so much for your help with this. Here is the complete debug message coming from the built in service test.

*** Service ***
Array
(
    [name] => Constant Contact
    [url] => http://www.domain.com/wp-content/plugins/forms-3rdparty-integration/3rd-parties/service_test.php
    [forms] => Array
        (
            [0] => gf_8
        )

    [success] => <div id="code" title="201"></div><h3>Thank you!</h3><p>Your interest preferences have been successfully recorded.</p>
    [failure] => <div id="code" title="400"></div><h3>We're Sorry!</h3><p>It appears that you were not added to our mailing list.
            This may be due to one or more of the following reasons:
            <ol>
                <li>You have misspelled your email address</li>
                <li>You did not choose a list to subscribe to</li>
                <li>The system may be busy. Please try again later</li>
            </ol>
            </p>
    [timeout] => 10
    [mapping] => Array
        (
            [0] => Array
                (
                    [lbl] => first name
                    [src] => input_12_3
                    [3rd] => FirstName
                )

            [1] => Array
                (
                    [lbl] => last name
                    [src] => input_12_6
                    [3rd] => LastName
                )

            [2] => Array
                (
                    [lbl] => email
                    [src] => input_3_2
                    [3rd] => EmailAddress
                )

            [3] => Array
                (
                    [lbl] => country
                    [src] => input_16
                    [3rd] => CountryCode
                )

            [4] => Array
                (
                    [lbl] => city
                    [src] => input_13
                    [3rd] => City
                )

            [5] => Array
                (
                    [lbl] => state
                    [src] => input_14
                    [3rd] => StateCode
                )

            [6] => Array
                (
                    [lbl] => Zip
                    [src] => input_15
                    [3rd] => PostalCode
                )

            [7] => Array
                (
                    [lbl] => fish
                    [src] => input_11_1
                    [3rd] => Lists[]
                )

            [8] => Array
                (
                    [lbl] => Corals
                    [src] => input_11_2
                    [3rd] => Lists[]
                )

            [9] => Array
                (
                    [lbl] => General
                    [src] => input_11_3
                    [3rd] => Lists[]
                )

        )

    [separator] => []
)

*** Post (Form) ***
http://www.domain.com/register/
Array
(
    [input_12_3] => User
    [input_12_6] => User
    [input_3] => user@domain.com
    [input_3_2] => user@domain.com
    [input_16] => US
    [input_13] => City
    [input_14] => AL
    [input_15] => 999999
    [input_11_1] => LIST1
    [input_11_2] => LIST2
    [input_11_3] => LIST3
    [is_submit_8] => 1
    [gform_submit] => 8
    [gform_unique_id] => 
    [state_8] => XXX
    [gform_target_page_number_8] => 0
    [gform_source_page_number_8] => 1
    [gform_field_values] => 
)

*** Post (to Service) ***
Array
(
    [timeout] => 10
    [body] => FirstName=User&LastName=User&EmailAddress=user%40domain.com&CountryCode=US&City=City&StateCode=AL&PostalCode=999999&Lists%5B%5D%5B%5D=LIST1&Lists%5B%5D%5B%5D=LIST2&Lists%5B%5D%5B%5D=LIST3
)

*** Response ***
Array
(
    [headers] => Array
        (
            [server] => cloudflare-nginx
            [date] => Fri, 07 Mar 2014 20:46:58 GMT
            [content-type] => text/plain
            [connection] => close
            [set-cookie] => __XXXX; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.domain.com; HttpOnly
            [vary] => Accept-Encoding
            [cf-ray] => XXXXXX
        )

    [body] => --- POST ---
Array
(
    [FirstName] => User
    [LastName] => User
    [EmailAddress] => user@domain.com
    [CountryCode] => US
    [City] => City
    [StateCode] => AL
    [PostalCode] => 999999
    [Lists] => Array
        (
            [0] => Array
                (
                    [0] => LIST1
                )

            [1] => Array
                (
                    [0] => LIST2
                )

            [2] => Array
                (
                    [0] => LIST3
                )

        )

)

--- GET ---
Array
(
)

--- META ---
Array
(
    [REQUEST_METHOD] => POST
    [QUERY_STRING] => 
    [HTTP_HOST] => www.domain.com
    [HTTP_REFERER] => 
    [HTTP_USER_AGENT] => WordPress/3.8.1; http://www.domain.com
)

--- HEADERS ---
(getallheaders)
Array
(
    [X-Real-IP] => XXXXXX
    [Host] => www.orafarm.com
    [X-Forwarded-For] => XXXXX, XXXXX
    [Connection] => close
    [Accept-Encoding] => gzip
    [CF-Connecting-IP] => XXXXXX
    [CF-IPCountry] => US
    [CF-RAY] => XXXXXXX
    [Content-Length] => 184
    [X-Forwarded-Proto] => http
    [CF-Visitor] => {"scheme":"http"}
    [User-Agent] => WordPress/3.8.1; http://www.DOMAIN.com
    [Accept] => */*
    [Content-Type] => application/x-www-form-urlencoded
)

    [response] => Array
        (
            [code] => 200
            [message] => OK
        )

    [cookies] => Array
        (
            [0] => WP_Http_Cookie Object
                (
                    [name] => __cfduid
                    [value] => xxxxxxx
                    [expires] => 1577145000
                    [path] => /
                    [domain] => .xxxxxx.com
                    [httponly] => 
                )

        )

    [filename] => 
)
@dmd33

Is it doubling up on the []? It looks like this -> &Lists%5B%5D%5B%5D=LIST1&Lists%5B%5D%5B%5D=LIST2&Lists%5B%5D%5B%5D=LIST3
would translate to this ->
&Lists[][]+List1&Lists[][]=List2&Lists[][]=List3

Constant Contact would want to see ->
&Lists[]=List1&Lists[]=List2&Lists[]=List3

I will try changing the field name to simply Lists and see if that fixes it.

@zaus
Owner

Yes I was just about to suggest that -- you don't need to suffix [] in the field mapping when you use [] as the separator

@dmd33

Working now. This is really great. You should consider making a paid plugin for Gravity Forms and Constant Contact. There are two other options out there but neither support list selection. As far as I can tell this is the only way to do it. The only problem is that is uses version 1 of their API and it is deprecated but supported for now. Maybe you could figure it out with version 2. I would pay for it for sure!
Thanks so much!

@zaus
Owner

Thanks! I'll merge this branch and push it to WP.org too.

Send me contact details through my site if you're interested in pursuing further/custom plugin development. ;)

@zaus zaus closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.