Is it possible to modify or add values to a Sitefinity form in any of the EventHub events (IFormValidatingEvent, FormSavingEvent, etc.)? It seems these events expose only "validating" controls or some other abstraction or interface rather than the underlying FieldControls themselves. This is true even of the IFormFieldValidatingEvent even though it claims to return the field being validated. The exposed controls have no setter and I see no path to the underlying FieldControl. How can I change a form field value or add a hidden field value in these events?
It can be done! :)
Heres a sample where I add in some data after it's submitted:
Thanks for answering and the example.
Does the IFormEntryCreatedEvent fire soon enough to change/add the values BEFORE the e-mail notifications, if any, are sent? I'm currently using the FormSavedEvent to add/modify after the fact, but it's too late in the lifecycle to affect the e-mails. Ideally, I'd like to alter these values before they are saved, but I'll take anything that precedes the e-mail notifications. I suppose I could override the notification logic for the forms in question, too, If necessary, but I'm trying to avoid messy and less maintainable "hacks."
I'm not 100% sure on that, maybe support could chime in?...but I would hazard a guess that you would maybe want to hook in before "Created"
There's a FormSavingEvent that returns you a list of the Controls to perhaps modify.
I'm looking at the lifecycle for IFormCreatedEvent now to see if it's soon enough. The controls returned by the IFormValidatingEvent, IFormFieldValidatingEvent and FormSavingEvent don't have a setter for the control's Value, so these events are useless for my purposes. Also, since they occur before the form is created or saved, there's no way to use forms manager to retrieve an Id to make the updates using them. At least I can't find one.
The only "solution" I found is, IMO, a hack. Trap the FormSaved event, use the GUID of the FormEntry to retrieve it using FormsManager and make and save/commit your changes.
The problem is that this fires the FormSaved event again, so you'll need logic to prevent duplicate actions--like sending emails--if you have them.
Can You help me please? how to get the saved FormEntry id in the FormSaved event?
I see anly the formid :(