You use rule-based forms to collect information from the responders of the form and, based on their input, display different fields of the form.
EXAMPLE: You have a form where the users fill out their address. You want to display the State field only to users whose address is in the United States. In this case, you can create a rule for this form that whenever a respondent selects USA in field Country, a field State is displayed. To other users the field State will be hidden.
PREREQUISITES: You can create rules only for MVC forms.
You can create conditions for any field of the form and the actions that you can specify after the conditions are met are the following:
- Hide or unhide fields of the form
- Take the user to a specific step, in case of multi-step forms
- Take the user to a specific page of your website
- Display custom messages
Precedence of rules
The rules are executed in the reverse order – the rule that you create last has the highest precedence.
Define the conditions
To create form rules, you must first create the form together with all of the fields and steps. Afterwards, to create a rule, perform the following:
- In the backend of Sitefinity CMS, navigate to Content » Forms.
- Open the form where you want to have rules.
- In the toolbar, expand More actions » Rules.
- Click Create a rule.
- Use the dropdown box to choose whether All or Any of the specified conditions must be met.
- In the next dropdown box, choose the field which you want to specify conditions for.
The dropdown box lists all the fields that you have created in the form.
- Choose how the selected field must meet the condition.
You can choose between:
- is – the user input must be exactly the same as what you entered in the next field.
- isn't – the user input must be different than what you enter in the next field.
- contains – the user input must contain what you enter in the next field.
- doesn't contain – the user input must not contain what you enter in the next field.
- is filled – the user must fill the field with any input.
- isn’t filled – the user must leave the field blank.
NOTE: If, as condition, you are using a field that is multiple choice or checkboxes, you do not have operators contains and doesn’t contain, because the input is predefined.
- In the next input field, enter the condition that the field must meet.
EXAMPLE: If you want to create a rule for all users whose country is the USA, in the first dropdown box select Country, in the second dropdown box select is, in the input field, enter USA.
To add more conditions, click the plus icon.
Define the actions
You can specify conditions for any of the fields of the form. When the form responder meets the conditions that you specify, you define the actions that are going to be executed.
Under THEN…, perform the following:
- In The dropdown box, select one of the following:
- Show field
In the next dropdown box, select which of the fields you want to display.
You can use this option in cases when you have already hided the field.
To hide a field, open the widget for editing and in select dropdown box Hidden field.
EXAMPLE: You want a field ABC to be hidden for everyone, except for a certain group of people. In this case, open field ABC for editing and select Hidden field dropdown box. Afterwards, create a rule to show field ABC, based on the desired condition.
- Hide field
In the next dropdown box, select which of the fields you want to hide.
NOTE: You can hide fields that have required input.
- Skip to step
You can use this option in case of multi-page forms.
In the next dropdown box, select the step where you want to take the user.
The dropdown box lists all the steps that you have created in the form.
- Go to page after submitting
In the next step, select the page from your website where you want to take the user after the form is submitted.
- Show message after submitting
In the paragraph box, enter the text of the message that you want to display.
- To add more actions, click the plus icon.
- After you are finished defining conditions and actions, click Create the rule.