Kentico 11, Bizform OnBeforeSave method - get form field values prior to save?

Tom Wisneski asked on March 6, 2020 18:31

Question: Using an online-form (Bizform), and in the OnBeforeSave method -- I am querying some SQL values. The values are required for calculations. The form itself takes end-user inputs for a calculator. However, the calculations can not take place before the end-user offers their input values. So what I am trying to do is to intercept the Kentico input field values on the submit click. This all has to be done prior to a save since the end product (results), get saved in the Kentico form table. Is there a way to get a Kentico form field in the code behind? Thanks in advance!

Correct Answer

Dmitry Bastron answered on March 6, 2020 19:16

Hi Tom,

According to the documentation of BizForm events you can do it. The following code should help:

[assembly: RegisterModule(typeof(CustomModule))]
public class CustomModule : Module
    public CustomModule()
        : base("CustomModule")

    protected override void OnInit()
        BizFormItemEvents.Insert.Before += InsertOnBefore;

    private void InsertOnBefore(object sender, BizFormItemEventArgs e)
        var formItem = e.Item;
        var text = ValidationHelper.GetString(formItem["submittedFieldName"], String.Empty);

        formItem["calculatedField"] = "result of calculation";
0 votesVote for this answer Unmark Correct answer

Recent Answers

Tom Wisneski answered on March 6, 2020 20:04

Dmitry - thank you for the reply & input. Just so I understand correctly...I should be using the InsertOnBefore method to capture a field value prior to a save (which would insert into the form table). Does that sound correct? Thanks. :)

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on March 6, 2020 20:16

Yes, you can also amend the data before it will be written to the database (look at the calculated field example above) and even cancel the write by calling e.Cancel() method if I'm not mistaken.

0 votesVote for this answer Mark as a Correct answer

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