I have a use case where we have multiple contact lists under our one account. The problem is that if a user has subscribed to a list in the past it will not add them to the new list instead it says email address is already subscribed.

What should happen is when the form is submitted it should check if the user is on the specific list that they selected (or the default list if the list options are not selected). If they aren't it should do a update_contact() and add the contact to the list.

Here is my first version starting on line 1148

Replace this existing code:

	if($contact):
		form_set_error('cc_email_'.$delta, t('Your email address is already subscribed'));
	else:

With this code:

    if($contact):
          foreach ($lists as $list):
	       $existing_contacts = $cc->get_list_members($list, $action = 'members');
			foreach ($existing_contacts as $existing_contact):
				if (array_search($contact['id'], $existing_contact)):
					form_set_error('cc_email_'.$delta, t('Your email address is already subscribed'));
				else:
					$updated_contact = $cc->update_contact($contact['id'], $user_email, $list);
				endif;
					
			endforeach;
		endforeach;
    else:

I slapped this together quickly in hopes that someone may be able to help me make this work for large contact lists. The problem is that the code above loops through every contact in the list. Any ideas on improving this?

Thanks!

Comments

justphp’s picture

Assigned: Unassigned » justphp

I'll look into this but what you describe is by design, probably best to have an option to update peoples lists or add to them if the email is already subscribed. The trouble with the block method is it's anonymous so anyone can edit others subscriptions.

bentekwork’s picture

Thank you for taking a peek. I understand your point about anonymous users but you can sign anyone up that you want if they are not a member on that account. So what would be the difference between that and adding someone's existing email to another list?

--Please read this with a tone that is not condescending in any way. I am just attempting a discussion and not saying that you are wrong.

justphp’s picture

Fair point.

anthony0perez’s picture

Bentekwork does your solution work for adding to a list even though they are signed up with another list in your constant contact account? Maybe not update a user but at least add them or their email address to that list.

aklump’s picture

Here is a patch to fix this issue. It adds a new configuration option if you don't want to support multiple lists.

aklump’s picture

Status: Active » Patch (to be ported)