Hi @mgyura and @motherny,
These updates aren’t completely seamless so you will have to update some code hard coding a few values but on the front end it is working perfect for us.
Browse to your gravityformsmailchimp folder -> open mailchimp.php
Scroll to line 592 OR search for “$merge_vars = $api->listMergeVars($config["meta"]["contact_list_id"]);” in the “private static function edit_page()” function.
Paste this line of code right below the line of code above.
//Added by dndco to allow for the G-Form mapping of Hidden text group names. array_push($merge_vars, Array("name"=>'INTERESTS', "req"=>"", "field_type"=>"text", "public"=>"1", "show"=>"1", "order"=>"7", "default"=>"", "helptext"=>"", "size"=>"25", "tag"=>"INTERESTS"));
This forces an element into the merge_vars array called INTERESTS which you will map to your hidden field on your G-form through your Admin.
You will most likely have to update the value assigned to “order” shown above. Order is where your interest group’s form element exists in your Mailchimp form.
So if your Mailchimp form has these elements … FName, LName, Email, Group Checkboxes … order would be set at 4 for this example as your Group Checkboxes are in the 4th spot/location on the Mailchimp Form.
Scroll to line 698 or search for “$merge_vars = $api->listMergeVars($list_id);”
Paste this line of code again below the above line and make sure to update your order value to match the order of your Mailchimp list.
//Added by dndco to allow for the G-Form mapping of Hidden text group names. array_push($merge_vars, Array("name"=>'INTERESTS', "req"=>"", "field_type"=>"text", "public"=>"1", "show"=>"1", "order"=>"7", "default"=>"", "helptext"=>"", "size"=>"25", "tag"=>"INTERESTS"));
Those two pieces of code will allow you to map your hidden G-Form element to a MailChimp form element called “INTERESTS” and will insert the group name into Mailchimp.
*** YOU HAVE TO MAKE SURE YOUR G-FORM HIDDEN ELEMENT NAME/VALUE MATCHES YOUR MAILCHIMP GROUP NAME VALUE EXACTLY. ***
ex. If your interest group for this form is “Fine Dining” then your hidden G-form element has to be “Fine Dining” spelled exactly the same.
Now we will update a user’s info if they already exist in the list.
Scroll to line 1059 or search for “$retval = $api->listSubscribe($feed["meta"]["contact_list_id"], $email, $merge_vars, "html", $double_optin, false, true, $send_welcome );”
Paste this code below the line of code above.
//Start of dndco’s code
if (!$retval) {
switch($api->errorCode) {
case '214' :
$retval = $api->listUpdateMember($feed["meta"]["contact_list_id"], $email, $merge_vars, "html", false);
break;
default:
$errormsg = $api->errorCode.":".$api->errorMessage;
// send e-mail to admin with MailChimp Error
$emailAdmin = get_option('admin_email');
// Your subject
$subject = "Gravity Form to MailChimp Error";
// Your message
$message = "An error occurred during MailChimp insert for user " . $email . " Error information: ";
$message.= $errormsg;
// send email
$sentmail = wp_mail($emailAdmin, $subject, $message);
break;
}
}
//End of dndco’s code
Code description: If $retval throws any type of error capture it and evaluate. Error code 214 means user already in list so we want to update info if error == 214. If error != 214 send an email to the admin of the WordPress site with the MailChimp error code, description and email address of user submitting the form.
Again it’s not elegant but it works for our situation and allows us to have one MailChimp list with multiple interest groups.
Hope this helps.
Posted 13 years ago on Tuesday May 10, 2011 |
Permalink