Mautic Community Forums

How to restart a campaign when a form is submitted?

Your software
My Mautic version is: 2.15.3
My PHP version is: 7.2.24

Your problem
We have the following double-opt-in system:

  • When someone fills in their email address in a Form, the Contact is added to a Segment called “pending-confirmation” through a form action.
  • A Campaign named “confirmation” uses “pending-confirmation” as its source of Contacts. The first step in this Campaign sends an email to the Contact containing a confirmation link.
  • The user clicks the link. The second step in the Campaign sees this page view, removes the Contact from the “pending-confirmation” segment and adds it to a Segment called “confirmed”.
  • This Segment is used as the source for the “main” Campaign, which sends out an email a day for 30 days.

These emails contain dynamic content, so people often re-subscribe after having completed the “main” Campaign once (which takes 30 days).

To allow for this, we have enabled the “Allow contacts to restart the campaign” option. This option doesn’t work properly in 2.15.3 due to issue #7338, but we have also applied the patch following these instructions. So I would expect it to work now… if the contact has actually exited the “pending-confirmation” segment.

However, what happens if they fill out the form while they’re still in the “pending-confirmation” Segment (and thus in the “confirmation” Campaign)? In that case, the Form’s action will do nothing, and they won’t get the confirmation email again. So if they have not received the first confirmation email, or deleted it, or whatever, they are now stuck in this state forever; resubscribing will do nothing for them.

What we need is a way to say: when this Form is submitted, do not only add the Contact to this Segment, but also restart any Campaigns associated with the Segment (or: also restart this particular Campaign) for this particular Contact.

Is there a way to do this?

Hmm, why don’t you simply send the email as a form action?

Two reasons.

One: form actions are executed immediately, whereas campaign membership is processed from a cron. So by the time the contact receives the email and clicks the confirmation link, the contact might not actually be in the campaign yet, so their click is not registered by the campaign.

Two: we replaced the “Visits a page” decision by a “Clicks email” decision, which requires the preceding step in the campaign to be a “Send email” action. The reason for this switch is that “Visits a page” can be triggered by anyone just by visiting the page, even if they haven’t received the email, as long as they have the original cookies from the sign-up form. So it’s not a waterproof double-opt-in solution, because anyone can sign anyone else up.

Meanwhile we do have a workaround: the sign-up form adds the contact to a special “initialize” segment which triggers an “initialize” campaign. This campaign just runs through some simple steps:

  • remove contact from “confirmation” campaign and “pending-confirmation” segment
  • add contact back to both of the above
  • remove contact from “initialize” campaign and segment.

They could still fill out the sign-up form a second time while they’re still in the “initialize” campaign, and in that case they wouldn’t get a second confirmation email. But that’s not a problem.

This workaround is not exactly intuitive, and it takes some extra cron runs (and thus time) until the confirmation email gets sent, so I’m still open to better solutions.

ok good!
(Funny, I wanted to suggest exactly that “hack” too but though I’d suggest the form action first :slight_smile: Thanks for sharing!)