Inheriting FormsControl - how can I add custom validation

Posted by Community Admin on 04-Aug-2018 19:36

Inheriting FormsControl - how can I add custom validation

All Replies

Posted by Community Admin on 30-Jan-2014 00:00

I have a specific form I have developed that inherits from the standard FormsControl. I need to be able to add an error message to the screen if custom condition of mine fails when submitted. This type of validation falls outside of what I can configure within the back-end, as it requires a web service call prior to submission.

How can I simply add an error message to the UI? Is there a collection of errors that I can append to, that, if any exist, will invalidate the form? Thanks.

Posted by Community Admin on 04-Feb-2014 00:00

Hello Ryan,

There is a blogpost which will help you achieve your requirement:
http://www.sitefinity.com/blogs/stanislav-velikovs-blog/2013/09/20/server-side-captcha-for-sitefinity-forms

What you seek is the following:

base.BeforeFormSave += new EventHandler<CancelEventArgs>(this.FormsControlCustom_BeforeFormSave);

By attaching to this event you could perform your validation and if the validation fails to call "e.Cancel = true;" which will cancel the form submission. At the end of this blogpost you can find a sample code which with only small modification will do the job for you.

Regards,
Vassil Vassilev
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items

This thread is closed