Using xProfile Data to Populate a WFFM - Part 4: Smart Form

Thursday, March 03, 2016 @ 12:30

By: Scott Gillis, Lead Consultant – After showing off the solution to Paragon's Digital Marketing Specialist, Matt Russo, his marketing gears began to crank into overdrive. He asked the question, "If a field can be pre-populated, why waste the visitor's time asking them to fill it in? Instead, could the field be hidden?". Since I had come this far, I figured why not dive into this challenge. So you get an unplanned Part 4 for Contact Facets and Web Forms for Marketers forms (WFFM).

Conveniently, Sitecore already provides a hide element action, we just have to create the conditional rule that triggers it.

Let's begin with the code side of the solution. I created a new class that inherits from Operator Condition. This provides some wiring under the hood for retrieving the value collected via the Rule Macro. The class declaration is:
public class ContactFacetExist<T>:OperatorCondition<T>: where T:RuleContext

Next, add a string property to collect the data from the Contact Facet Selector Macro to be used during the execution of the rule.
public string ContactFacetMemberPath { get; set; }

Finally, override the Execute method, where all of the magic happens. For our rule, we want to check if the current contact has populated a specific Contact Facet Member. We will retrieve the specific facet member via our custom Rule Macro written in Post Three – Rule Macro for Facet Selection, then check to see if it is populated. That's it for the code.

The front-end declaration is pretty straight forward and very similar to the creation of the custom action that was written in Post One – Auto-Populate a WFFM Field.

  1. Open up the Content Editor and navigate to Sitecore \ System \ Settings \ Rules \ Elements \Visitor [Feel free to pick any folder. For this action, visitor is most appropriate]
    Image One - Sitecore Tree Click Options
  2. Right-click and insert a new Condition
    Image Two - Right-click Options
  3. Complete the Text field with the verbiage that will be seen and interacted with by the end user
  4. Complete the Type field with Namespace.Class Assembly of the custom supporting code that handles the conditions behavior

The final Sitecore Artifact should look like the following:

Image Three - Sitecore Backend Options
Image Four - Field/Value Table


Form setup would look like the following for a first name field:

Image Five - Sitecore Backend Options


The above will just hide the field, so we will never collect this information as part of the forms report. To do that we need to add a second action using are action created in Post Two – Read from Contact Facet Action. The final field rule set would be:

Image Six - Sitecore Backend Options


Now that the interactions of our site visitors have been simplified, hopefully they will be convinced to submit more requests and engage with us more because they are not repeatedly asked for their information.

Check-out the full source solution on GitHub. Until commenting gets implemented, feel free to tweet me questions or comments @thecodeattic or on Sitecore Slack Community as @gillissm.

Entire Series

Post One – Auto-Populate a WFFM Field
Post Two – Read from Contact Facet Action
Post Three – Rule Macro for Facet Selection
Post Four – Smart Form



Scott Gillis, Lead Consultant at Paragon and 2017 Sitecore MVP, has been working with Sitecore for several years. He has a deep passion for helping clients leverage their content and data into powerful new capabilities in Sitecore and has produced successful outcomes as the technical lead on numerous, complex implementations. Recently, Scott has been focusing on helping these clients take advantage of the wealth of data collected by Sitecore Experience Analytics.