I'm digging up an old post, but I had the same issue and wanted to share the solution we found for future users.
Note that this method solves two problems : it makes it easier to integrate a subscribe option in your form (no need to display public groups), and it solves the issue of not wanting a contact to be able to un-subscribe via the petition if they tick "No".
We solved this by using the CiviRules extension, which can be installed easily through Administer
=> System Settings
=> Extensions
=> Add New
.
Next, we create a new group of custom fields in Administer
=> Customize Data and Screens
=> Custom Fields
. We make two fields : one that will be displayed as a Yes or No at the end of the petition to subscribe, and one to indicate that the subscription status is pending (important to not send two mails of subscription activation !).
After that, you should find the two fields on your contact pages like on this image.
Then, go to Administer
=> CiviRules
=> Manage rules
. In there you gotta create 2 rules to make sure that when your contact says "Yes" to the variable indicating a petition subscription (and that he's not already in your newsletter group), then he'll be added.
Here are the rules in detail :
- Newsletter subscription after petition (Contact already exists)
With this rule, an existing contact that signs the petition but wasn't in the mailing list will be added as "pending" (and will thus receive the confirmation email for the subscription). The Pending Petition Newsletter Subscription
variable is here to prevent the rule from re-triggering itself, as adding the contact to the group counts as a contact change. This prevents the rule from sending a second email of confirmation for your mailing list.
This rules also works when a new contact is created, even though the trigger is "Contact changed".
Linked Trigger
Contact of any type is changed
Linked Condition(s)
Field Value Comparison Contact.Newsletter Subscription Petition = 1
AND Field Value Comparison Contact.Pending Petition Newsletter Subscription = 0
AND Contact (not) in Group(s) Not in selected groups (newsletter mailing list)
Linked Action(s)
Create Pending Group Subscription Subscribe contact to group(s): newsletter mailing list
Set Custom Field on contact Set 'Pending Petition Newsletter Subscription' to 'Yes'
- Remove "Pending" status variable for petition newsletter subscription once group is joined
This rule removes the pending status. Not vital, but only used for the case where the contact un-subscribes from the group and wants to re-subscribe through the petition form.
Linked Trigger
Contact is added to Group
Linked Condition(s)
Field Value Comparison Contact.Newsletter Subscription Petition = 1
AND Field Value Comparison Contact.Pending Petition Newsletter Subscription = 1
AND Contact (not) in Group(s) In one of selected groups (newsletter mailing list)
Linked Action(s)
Set Custom Field on contact Set 'Pending Petition Newsletter Subscription' to 'No'