How to prevent double entry of record in dynamic forms

Topics: Customizing Orchard, Writing modules
May 28 at 11:52 AM
Edited May 28 at 1:00 PM
I will love to know how to use dynamic from in Orchard to prevent double entry of record like submiting of more than one phone number per different users and generating a unique number from thier form.
I have been having difficulty in activating code generation and hence creating modules in Orchard 1.10
May 28 at 7:04 PM
To prevent double entries where the rule for duplicate submissions is defined by custom logic (such as duplicate phone numbers), you could do either of the following:
  1. Implement a custom form event handler by deriving a new class from FormEventHandlerBase (in the Orchard.DynamicForms.Services namespace) and override the Validating method. This method receives a context argument that provides you with the submitted values. Since form submissions are stored as database records, you can query that table by looking for existing records with the specified phone number. If it exists, simply add a model validation error (the ModelState is provided via the context argument).
  2. If you want to be able to configure which form field elements are to be treated as unique, you could extend the form field elements in a generic manner by creating your own element driver, similar to the BindingsElementDriver. This way you can add a property to all elements that derive from FormElement. Then do the same as suggested I suggested in point 1: implement a custom form event handler, but this time checking for duplicate records based on elements that are configured to be 'unique'.
Regarding your troubles with activating code generation, I would create a separate thread for that and explain what you tried and how it failed (what errors, if any, are you seeing for example).
Marked as answer by Xtremrules on 5/29/2016 at 4:59 AM
May 29 at 12:06 PM
Thanks, that really help. I have finally been able to activate code generation and hence create modules. You need not create a new thread for that.
May 29 at 12:24 PM
I am glad to hear it.