Tailwind Logo

Logic functions that can be used in Forms

XM Cloud

Published: 2024-08-28

When using Sitecore Forms, a mechanism called "logic" is provided. By using this, you can implement things like not displaying unnecessary questions in order to increase the response rate for forms, etc., without having to develop anything.

Checking the logic

The Logic icon is located in the menu on the screen where you are creating the form. It is the second icon from the right of the six icons at the top.

formslogic01.png

Clicking on the icon will take you to the screen where you can add logic. The Add logic button is located in the top right.

formslogic02.png

Add form fields

The form we created last time is a little lacking in terms of logic, so we'll change the items. On the second page, we'll change it so that three options are displayed as items.

formslogic03.png

Add logic

Now that we have more questions, we will add logic to control whether or not the second page is displayed when the first question is checked.

First, click the Add logic button and an empty rule will be displayed.

formslogic04.png

In the first field, you can select the item you want to use as the target of the logic.

formslogic05.png

When you select a question item, you can check the choices used in that field.

formslogic06.png

For example, if you want to create a rule that displays the Content field when Content is selected, you would set it up as follows.

formslogic07.png

After making the above settings, let's check how it works when you actually select an item in the preview, and when you don't.

formslogic08.gif

If you make a selection, you can see the items displayed on the next page.

Prepared Logic

The items prepared in the logic are as follows.

  • Regarding the rules, the items for the field are
    • is equal to
    • is not equal to
    • is empty
    • is not empty
  • As for actions,
    • Hide field
    • Show field
    • Make a field required
    • Make a required field optional

The above is the combination. This logic is also effective for display/non-display actions on the same page.

Control of Show/Hidden within the page

For example, it is also possible to create a form that displays a list of manufacturers when the user selects "Yes" to the question "Do you have a car? In this case, place checkboxes as shown below so that the user can select a manufacturer from the list.

formslogic09.png

If you have a car, create a logic to display a list of manufacturers.

formslogic10.png

If you check the box to confirm that it works in the preview, you can check that the item is displayed.

formslogic11.gif

Summary

By adding logic to the form, it is possible to optimize the form, for example by displaying only the questions you want answered, or by asking people to add related information. This makes it possible to provide people with the option of only answering the minimum number of questions. And for those providing the form, it is possible to implement the display and non-display of required fields without having to develop them.

Tags