Forgot Password with WFFM & EXM – Part 3


In the previous post we set up a form and email to verify the user’s email address before we allow them to reset their password.  This post will show how to update the user’s state in response to the click-through from the verification email.

When a user clicks on the link in the email, we want to register the Validated Email goal.  This will trigger the engagement plan to move the user to the Pending Reset state.  However, we only want to register the goal and put the user in that state, if the timeout for the email verification has not passed.  This is where Sitecore falls just a bit short with it’s out-of-the-box functionality.  As far as I have found, there is no way to conditionally trigger a goal or put the user into a particular state of an engagement plan.  We will need to make a couple of tweaks to get this ability.

EXM creates a campaign for each email.  The campaign is triggered when a user clicks on a link in the message as part of the redirectUrl pipeline.  When Sitecore triggers a campaign, it runs another pipeline: triggerCampaign.  This pipeline has a processor named RunRules that looks for a field named “Rules”.  The odd thing is, there is no such field on the Campaign template.  Normally, I would try to avoid changing a system template, but since there is already code looking for the field, don’t feel too bad about it in this case.

In the Content Editor, go to /sitecore/templates/System/Analytics/Campaign and add a Rules field named Rule.  Set the source to /sitecore/system/Settings/Rules/Campaigns.

Add Rule field to Campaign template

We want to add a rule to this newly added field on the the campaign items that will register a goal if the user is in the right state of our engagement plan.  Unfortunately, Sitecore didn’t make this as easy as they could have.  There is a condition that checks if the user is in an engagement plan state, but it unnecessarily is limited to only be used within engagement plans.  Sitecore also does not provide an rules engine action to register a goal.  We will need to correct both of these oversights.

Create a class named IsInEngagementStateCondition with the following code:

In the content editor, duplicate the /sitecore/system/Settings/Rules/Definitions/Elements/Engagement Automation/Is in Specific State item and name it something like “Is in Engagement Plan State”.  Make sure you can distinguish it from the original.  Edit the condition to have the Text “where the current visitor is in the [StateId,Tree,root={4497A9BE-0A00-4EE4-9AE0-50D6CBB4FAB2},specific] engagement plan state” and set the type to the signature of your condition class.

Is In Engagement Plan State Condition

Create a class named RegisterGoalAction with the following code:

In the Content Editor, go to /sitecore/system/Settings/Rules/Definitions/Elements/Visit and insert an Action item named Register goal.  In the Text field, enter “Register the [GoalId,Tree,root=/sitecore/system/Marketing Control Panel/Goals,specific]  goal”.  In the Type field enter the signature for your RegisterGoalAction class.

Create Register Goal action

Go to the campaign item for your Password Reset Email Verification message.  Open the editor for the Rule field that you just added,  Select the “where the current visitor is in the specific state in the engagement plan” condition, click the specific link and select the Pending Email Validation state.  Select the “Register the specific goal” action, click the specific link and select the Validated Email goal.

Add a rule to the campaign

At this point, you should be able to test that when submit your email address on the Forgot Password page, you get an email.  If you click the link in that email, your visitor record should be moved to the Pending Reset state of the engagement plan.  In the final post of this series we will wrap up the front-end by allowing the user to reset their password.