Quantcast
Channel: DevNet Questions
Viewing all articles
Browse latest Browse all 8832

Set error message of Kentico BizForm with method registered to BizFormItemEvent

$
0
0
I have registered a method to BizFormItemEvent.Insert.Before that checks if a user already exists with an email address provided in the form and creates a user if it doesn`t. If the user does exist with that email address, then I want to display an error message. Problem is, if you try to call e.Cancel() or throw an exception, the BizForm just displays the generic "An error occurred when saving data. Please see event log for more details" message, and I`m not sure how I can alter that message.Here's what I'm doing so far:using CMS.Base; using CMS.OnlineForms; using System; /// @summary@ /// Partial class that allows you to register custom handler methods and classes. /// Adds the CustomFormHandlers attribute to the partial class. /// @/summary@ [CustomFormHandlers] public partial class CMSModuleLoader { /// @summary@ /// Custom attribute class. /// @/summary@ private class CustomFormHandlers : CMSLoaderAttribute { /// @summary@ /// Called automatically when the application starts /// @/summary@ public override void Init() { BizFormItemEvents.Insert.Before += FormItem_InsertBeforeHandler; } /// @summary@ /// Handles the form data when users create new records for forms /// @/summary@ private void FormItem_InsertBeforeHandler(object sender, BizFormItemEventArgs e) { BizFormItem formDataItem = e.Item; if (formDataItem != null @@ formDataItem.BizFormClassName == "bizform.formname") { // CreateUser returns false if a duplicate email is found if(!CreateUser(formDataItem)) { // Something needs to happen here that // changes the error message of the bizform // e.Cancel(); throw new Exception("A user with this email address already exists."); } } } } }

Viewing all articles
Browse latest Browse all 8832

Trending Articles