The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Update MailChimp Entry when using frm-entry-update-field shortcode

Labels

This Discussion is public

Notifications

Hi all,

I had a client whom had issues updating MailChimp mergetags when using the shortcode (https://formidableforms.com/knowledgebase/insert-a-link-to-change-the-value-of-a-single-field/) on their custom display.

After quite some time debugging the problem we came up with a solution. I thought I would share the results below in case anyone else had the same issue.


add_action('frm_after_update_field', 'frm_trigger_entry_update');
function frm_trigger_entry_update($atts){
  /*
   * Blue Liquid Designs MailChimp Update Fix
   * www.blueliquiddesigns.com.au
   * Fix: Ensure Mailchimp fires when using AJAX field hook .
   * See https://formidableforms.com/knowledgebase/insert-a-link-to-change-the-value-of-a-single-field/ for more details
   */	
	
  $entry = FrmEntry::getOne($atts['entry_id'], true);

  /*
   *
   * Mailchimp needs to have $_POST['frm_mailchimp'] set to run the update
   * It also needs the $_POST field data too
   */
   $_POST['frm_mailchimp'] = 1;   
   $fields = FrmFieldsHelper::get_form_fields($entry->form_id);
   $values = FrmAppHelper::setup_edit_vars($entry, 'entries', $fields);  
   
   /*
    * Now we have all the fields and their values we will put them in the $_POST['item_meta'] array ready for mailchimp
	*/
	foreach($values['fields'] as $id => $data)
	{
		$_POST['item_meta'][$id] = $data['value'];	
	}
	
	/*
	 * Finally we need to match the email field and also assign it to the post array to ensure the entry is updated
	 */
	 global $frmdb;
	$form_options = $frmdb->get_var($frmdb->forms, array('id' => $entry->form_id), 'options');
	$form_options = maybe_unserialize($form_options);
	
	if(isset($form_options['mailchimp']) or $form_options['mailchimp'])
	{
		foreach($form_options['mlcmp_list'] as $id => $list_options)
		{
			/*
			 * MATCH THE EMAIL
			 */
			 $_POST['frm_mailchimp_email'] = $_POST['item_meta'][$list_options['fields']['EMAIL']];
			 continue;
		}
	}
   
  do_action('frm_after_update_entry', $entry->id, $entry->form_id);
}

Note: Along with Mail Chimp updating, the above code will also fire notifications (and anything else attached to the frm_after_update_entry action. If you only want to update Mail Chimp then replace the line 'do_action('frm_after_update_entry', $entry->id, $entry->form_id);' with 'FrmMlcmpAppController::send_to_mailchimp($atts['entry_id'], $entry->form_id);'.

Discussion closed.