I would like to add custom validation for a EPiServer Form, and have found information about how to add validators to specific fields.
What is the best approach for form wide validation, for example:
- Validate that not more than 10 forms are submitted from the same IP-range.
- Validate that if textbox1 and textbox2 are left empty, textbox3 are required.
You could try hooking into the FormsSubmitting or FormsStepSubmitted events:
I hooked into the FormsSubmitting-event and was able to get previous submissions, and check number of earlier submissions from the same IP.
I used the following code to get the previous submissions:
var formsDataStore = ServiceLocator.Current.GetInstance<FormsDataStore>();
var resultset = formsDataStore.Get(submittingEventArgs.FormsContent.ContentLink, null, null, null, null, false, null);
This works fine as long as I'm logged into EPiServer, but for unauthenticated users resultset.Data is null.Can this be done for unauthenticated users? I would prefer not to use the Forms.ServiceApi