Biz Form Validation From Server Side

Aasim Khan asked on July 4, 2015 09:52

Hello,

I created one Biz Form. So i want to do server side validation programmatically . Please suggest me how to do?

Thanks,

Regards, Aasim Afridi

Recent Answers


Virgil Carroll answered on July 4, 2015 19:28

You can use the BizForm control in your own web part and use one of the event handlers in this article https://docs.kentico.com/display/K8/Reference+-+Global+system+events#Reference-Globalsystemevents-BizFormItemEvents

There you can do server side validation and either submit the form or stop the process. There are a couple of other article in the documentation around this like https://docs.kentico.com/display/K8/Working+with+form+data+using+the+API#WorkingwithformdatausingtheAPI-Handlingformevents

0 votesVote for this answer Mark as a Correct answer

Aasim Khan answered on July 5, 2015 19:38

Hello Virgil Carroll,

Thanks for giving the answer. I am using this event Handler(Insert.Before). I have written all the code but i don't know how to stop the process of form And how to return on Form page.

Please advice me.

Regards, Aasim Afridi

0 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on July 6, 2015 00:14

Aasim,

I am actually not sure if there is a Online Form command to stop the processing (someone else might know). My suggestion would be to do all your code in a Try Catch and if your server side validation raises an issue, throw a .NET error to stop the form from processing.

Tx, Virgil

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 6, 2015 18:49

Aasim use e.Cancel(); to cancel the current event execution.

1 votesVote for this answer Mark as a Correct answer

Aasim Khan answered on July 7, 2015 22:02

Thanks Virgil and Brenden.

I am able to cancel the execution using e.cancel() method. But Using this i am getting this message at top of the form "An error occurred when saving data. Please see event log for more details.". Either i want to customize this message or please let me know how can i use here viewBiz.StopProcessing = true;.

Regards, Aasim Afridi

0 votesVote for this answer Mark as a Correct answer

Victor Hugo Garcia answered on August 31, 2015 21:10

Did you find how to customize the error message?

0 votesVote for this answer Mark as a Correct answer

Daniel Maley answered on June 1, 2016 20:56 (last edited on June 3, 2016 19:53)

After a few hours of digging I did finally find this article which appears to resolve the issue above. Basically once you have tapped into the correct global events (Update\Insert) you can simply throw a generic exception with a specified message and the screen will handle it gracefully. Note: the message is not field specific but global to the entire form. Update: It also appears this solution will not work for Custom Forms (BizForms) and is limited to page type fields or custom module classes. When implemented on a custom form I am still seeing the generic error message above when throwing an exception with a specified message.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.