I came across a scenario where i implemented a custom validation on Sitecore 9 Forms. Sharing my knowledge here. You can achieve this in three simple steps.
Step 1: Create custom validator
Create a custom validator under /sitecore/system/settings/forms/validation based on Validation(sitecore/templates/System/Forms/Validation) template like below
Step 2: Fill out the fields
Fill out your own regex and error message. You can copy the Type value from other validator.
Step 3: Assign the custom validator
You can now add the new custom validator to any Form fields( /sitecore/system/Settings/Forms/Field Types). All set and no code required!
Hope you found this blog helpful. Any questions, please leave a comment.
Have you submitted a form and it returned with this error ‘The required anti-forgery cookie “__requestVerificationToken” is not present’? If so, here is the resolution.
This could be because of caching. Can you check if your rendering component or container/page level caching check box is checked? if so, unchecking the caching will fix the issue.
Also here is quick check you can do to see whether your form is cached – Inspect the form and check the _requestverificationtoken value like below and refresh the page – do you see same value now? if so, your form is in cache!
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.