We have explored creating a Custom Form Element – Rich Text Field and Creating a Custom Form Field Validator earlier. Ever since I wrote those articles, I always wanted to explore creating a Custom Submit Action. But rather than just writing about how to implement a custom submit action, I thought I will pick some meaningful business case that demands a custom submit action and explore it from a marketing perspective.
Finally, after several months, when I was having a discussion with one of my ex-colleague I came across this business case. I thought, I will explore it and share my experience here.
So…let’s get started.
We will create a custom submit action, that creates a contact and we’ll add the contact to different Sitecore Lists based on their gender. Once this list is populated with corresponding contacts, we can use those list for campaigns using E-Mail Experience Manager or Marketing Automation.
So it’s pretty much straight forward now, in this article, we’ll be
Creating a Simple Form that uses a-> Custom Submit Action, to -> Create Contact based on that user info submitted -> Add the contact to Male Contact List or Female contact List based on the gender value they have specified in the form.
We will be using a simple Sitecore Form, no complex fields. In fact, I created one registration form long back. I will use that for our case.

However, we’ll be using our newly created Custom Submit Action – Create Contact.

Creating a Custom Submit Action:
- To create a custom submit, create a class that inherits from SubmitActionBase<string>. This SubmitActionBase is available in Sitecore.ExperienceForms assembly.
- This SubmitActionBase has a Execute method which we will be overriding and writing our custom logic there.

- This execute method has Sitecore FormSubmitContext as one of the arguments. This FormSubmitContext had fields that provide details about the Submitted Form like the field values, if it has any errors, page in which the form is submitted from etc.

- We will be reading the values of the form fields submitted by the user. And assign it to a custom user model.

- Based on the field type the way in which we read the field value differs. In our case, we had a radio button/date and a DropDownList.


- Once the User object is assigned values, we will pass that to CreateContactandSubscribetoList Helper method that creates contact based on it.
- Creating a contact is simple, instantiate an Xconnect Client, create a contact object, set the required facets i.e., Personal Facets, E-Mail/PhoneNumberList facet in our case.

- Creating a Sitecore Submit Action Item.
- Under /sitecore/system/Settings/Forms/Submit Actions, create a new Submit Action named CreateContact based on Submit Action template(Available in the Insert Options)
- In Settings session, Model Type add the class name along with the full namespace.

- This custom submit action created will be added to the list of available submit actions in the Forms Editor and we can assign it to our submit button.

Create two Lists:
- By open List Manager from Launchpad, click Create Empty Contact List. Create two such lists, one for Male and one for Female.

- Make a note the IDs of these two lists. We need the List ID to subscribe a contact to that list.
- The IDs of these two list can be obtained from Marketing Control Panel. -> /sitecore/system/Marketing Control Panel/Contact Lists/


Add Contact to the List based on the gender:
- To add a contact to a list programmatically, we can use ISubscriptionService available in the List Manager API -> Sitecore.ListManagement.Xconnect.Web assembly.
- We can add the contact to the list using the Contact ID and List ID.
- Add this logic to CreateContactandSubscribetoList helper class.
- In a real time scenario, instead of hard coding the list values, we can fetch them from configs or constants.

So, now we have everything in place, let us submit a form and see based on the gender, the contact gets added to the corresponding list.


There we go, the contact got added to the male list. Similarly, the contact’s session details will also be present in Experience Profile as well as we have included the relevant code.

This is sample use case. As you can see, we are obtaining the DOB as well. Similarly, we can create a list of male/female contacts between 18-30; 30-40 and 40 & above. We can create list based on the country if we collect address. And many more such scenarios. This way we can conduct campaigns that are more relevant to the contacts belonging to this list. Will write an article on how we can setup some campaigns based on these lists in the coming days.
The article related to this business case can be found here.
One thought on “Sitecore – Custom Submit Action – Create Contact – List Management”