Sitecore Explorations

Sitecore 9 Forms: Success message

Sitecore 9 form feature is awesome and simple to work with. It is more like Visual Studio Toolbox and you can drag and drop the fields.

I had a requirement from Client asking for Ajax form and wanted to show Confirmation/Success message after the form is submitted. Out of the box, this is achievable with the Form.

Here is a small guide on how to create a form with confirmation message:

1. Select Forms from Dashboard.

2. Click Create button.
3. Select blank form.

4. Drag a page for main content.
5. Drag a another page for confirmation message.
6. Design the fields according to needs. Here I’m doing Email Signup form. You can add field validation and css-class as needed.

Please make sure you have these scripts in Layout.cshtml.


7. On the submit button, set the Navigation step to Next instead of submit. This does the trick to show the confirmation page.

7. Save the form.
8. Now you can see the form in Content Editor.

Don’t forget to publish the form and place it on a web page under MVC layout. Here is Sitecore documentation on Adding a form to webpage.

Happy Sitecoring.


Pattern Matching in C# 7.0 Switch Statements

I was trying to figure out what would be the best way to list out partial views based on Model type and found C# 7.0 new feature ‘Pattern matching in switch statements’ would be great fit for the scenario.

Before only string/integer can be compared, now you can compare on any type of object. Below is the example shows switch case based on Model Interface type.

@model Synthesis.IStandardTemplateItem

@switch (Model)
case INavigationColumnItem nci:
//Take any action
case IColumnNavigationFolderItem ncfi:
//Take any action
case IHeaderLogoItem hli:
//Take any action
case IHeaderNavigationLinkItem hnli:
//Take any action
case IHeaderPhoneNumberItem hpni:
//Take any action

Checkout more cool new C# 7.0 features here. Happy coding.