Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

EPiServer Forms - validation across multiple fields

Vote:
 

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.

#161192
Oct 07, 2016 11:13
Vote:
 

You could try hooking into the FormsSubmitting or FormsStepSubmitted events:

http://world.episerver.com/add-ons/episerver-forms/handling-events-for-Episerver-forms/

#161194
Oct 07, 2016 14:39
Vote:
 

Thanks!

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

#162852
Edited, Oct 18, 2016 10:42
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.