Prevent Duplicate Online (BizForm) Entries

Larry Lim asked on August 24, 2018 21:43

I have been trying to build a custom form control to do the following when you click 'submit':

  • 1) Get the active on-line form field value(s) - - (bizForms)
  • 2) Query Recorded BizForm data

  • I am able to query the BizForm data so step #2 is not an issue. However, I cannot read or capture the form field value to use in logic coding within the OnBeforeSave control.

    What I am using: Kentico 10
    Examined: kentico 10 form API doc examples to build the following Custom Form Control:

  • viewBiz_OnBeforeSave
  • Where I am stuck is that I am unable to get the form field values on the form.

    So my logical process for this is:
    a) User enters name
    b) Form Control triggers after 'submit' to use the 'OnBeforeSave' control
    c) In the control it reads through already stored form data and checks entered field value for duplicates
    d) If a duplicate is found -> stop the form function and display 'Already submitted your entry' message

    • Form Example Name: 'GetAcknowledgement'
    • Text-Field on form: 'UserName [enter name]' - - - -> (so the field name is 'UserName')

    Tried using the following methods below that have had no success and I just copied how I found it by google searching/KenticoDevNet searching:

    • string nameFormValue = CMS.Helpers.ValidationHelper.GetString(Form.GetFieldValue("UserName"), "");
    • string nameFormValue = form.GetFieldValue("UserName"), "");

      Any recommendations?

    Correct Answer

    Larry Lim answered on August 28, 2018 17:18

    I figured out what I needed to do to make my BizForm work and the article Peter mentioned pointed me in the right direction.

    I wanted to detail what I needed to put in place to make sure my code was working:
    --> Make sure you register the function in the 'protected override' code... below is where I added the "viewBiz.OnBeforeSave" Code`

        //  THIS IS FROM:  protected override void OnLoad(EventArgs e) call code
        //  add in control functions here--  otherwise it will not work!
        //  controlling the 'OnBeforeSave' - to check for duplicates!
        viewBiz.OnBeforeSave += viewBiz_OnBeforeSave;
        viewBiz.OnAfterSave += viewBiz_OnAfterSave;

    Get table data with:

     // Loads the form's data  (already in Kentico Docs for API)
            ObjectQuery<BizFormItem> data = BizFormItemProvider.GetItems(className);

    Capturing data and getting form values I had the code below:

    // Get Associate name from data-table to verify they had done an acknowledgement
                string associateIDValue = item.GetStringValue("AssociateID", "") as string;
                string registrationName = viewBiz.GetFieldValue("AssociatesName") as string;

    IMPORTANT: You can capture form field values with:
    string STRINGNAME = viewBiz.GetFieldValue("FORMFIELDNAME") as string;

    Thanks for the information Peter- it helped me out!

    0 votesVote for this answer Unmark Correct answer

    Recent Answers

    Peter Mogilnitski answered on August 24, 2018 22:07 (last edited on August 24, 2018 22:30)

    I think it can be prevented on database level, i.e. you will have unique constraint on username column (i.e you can't have 2 rows with the same user name). Another option is to implement server side validation(scroll down to the example at the bottom of the page). Just instead of checking for the last submitted - you can check for the existing record with the same username, smothering like:

    var item = BizFormItemProvider.GetItems(ClassName).Where("Username = 'test'").FirstOrDefault()
    if (item != null) {...}
    1 votesVote for this answer Mark as a Correct answer

    Larry Lim answered on August 24, 2018 22:30

    Thanks Peter- I am checking the information out and will post if this helps solve my issue!

    0 votesVote for this answer Mark as a Correct answer

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