/// <summary> /// Raises the form validating event. /// </summary> /// <param name="formEntry">The form entry.</param> /// <param name="formFields">The form fields.</param> /// <param name="collection">The form collection.</param> /// <param name="files">The files.</param> /// <returns>Whether validation succeeded.</returns> protected virtual bool RaiseFormValidatingEvent(FormEntryDTO formEntry, Dictionary <string, IFormFieldController <IFormFieldModel> > formFields, FormCollection collection, HttpFileCollectionBase files) { var postedData = this.GetPostedData(collection, files, formFields); var formEvent = this.eventFactory.GetFormValidatingEvent(formEntry, postedData); return(!this.ValidationEventFailed(formEvent)); }
/// <summary> /// Raises the before form action event. /// </summary> public virtual bool RaiseBeforeFormActionEvent() { var manager = FormsManager.GetManager(); var form = manager.GetForm(this.FormId); var formEntry = new FormEntryDTO(form); var formEvent = this.eventFactory.GetBeforeFormActionEvent(formEntry); return(!this.IsEventCancelled(formEvent)); }
/// <summary> /// Validates the form against the preset submit restrictions. /// </summary> protected virtual bool ValidateFormSubmissionRestrictions(FormsSubmitionHelper formsSubmition, FormEntryDTO formEntry) { string errorMessage; var isValid = formsSubmition.ValidateRestrictions(formEntry, out errorMessage); return isValid; }
/// <inheritDoc/> public virtual SubmitStatus TrySubmitForm(FormCollection collection, HttpFileCollectionBase files, string userHostAddress) { var manager = FormsManager.GetManager(); var form = manager.GetForm(this.FormId); var formEntry = new FormEntryDTO(form); var formSubmition = new FormsSubmitionHelper(); if (!this.ValidateFormSubmissionRestrictions(formSubmition, formEntry)) return SubmitStatus.RestrictionViolation; if (!this.IsValidForm(form, collection, files, manager)) return SubmitStatus.InvalidEntry; var formFields = new HashSet<string>(form.Controls.Select(this.FormFieldName).Where((f) => !string.IsNullOrEmpty(f))); var postedFiles = new Dictionary<string, List<FormHttpPostedFile>>(); for (int i = 0; i < files.AllKeys.Length; i++) { if (formFields.Contains(files.AllKeys[i])) { postedFiles[files.AllKeys[i]] = files.GetMultiple(files.AllKeys[i]).Where(f => !f.FileName.IsNullOrEmpty()).Select(f => new FormHttpPostedFile() { FileName = f.FileName, ContentLength = f.ContentLength, ContentType = f.ContentType, InputStream = f.InputStream }).ToList(); } } var formData = new List<KeyValuePair<string, object>>(collection.Count); for (int i = 0; i < collection.Count; i++) { if (formFields.Contains(collection.Keys[i])) { formData.Add(new KeyValuePair<string, object>(collection.Keys[i], collection[collection.Keys[i]])); } } formEntry.PostedData = formData; formEntry.Files = postedFiles; formSubmition.Save(formEntry); return SubmitStatus.Success; }
/// <summary> /// Raises the form validating event. /// </summary> /// <param name="formEntry">The form entry.</param> /// <returns>Whether validation succeeded.</returns> protected virtual bool RaiseFormValidatingEvent(FormEntryDTO formEntry) { var formEvent = this.eventFactory.GetFormValidatingEvent(formEntry); return(!this.ValidationEventFailed(formEvent)); }
/// <summary> /// Raises the form saving event. /// </summary> /// <param name="formEntry">The form entry.</param> /// <returns>Whether processing should continue.</returns> protected virtual bool RaiseFormSavingEvent(FormEntryDTO formEntry) { var formEvent = this.eventFactory.GetFormSavingEvent(formEntry); return(!this.IsEventCancelled(formEvent)); }
/// <summary> /// Raises the form saved event. /// </summary> /// <param name="formEntry">The form entry.</param> protected virtual void RaiseFormSavedEvent(FormEntryDTO formEntry) { var formEvent = this.eventFactory.GetFormSavedEvent(formEntry); EventHub.Raise(formEvent); }
/// <summary> /// Validates the form against the preset submit restrictions. /// </summary> protected virtual bool ValidateFormSubmissionRestrictions(FormsSubmitionHelper formsSubmition, FormEntryDTO formEntry) { string errorMessage; var isValid = formsSubmition.ValidateRestrictions(formEntry, out errorMessage); return(isValid); }
/// <inheritDoc/> public virtual SubmitStatus TrySubmitForm(FormCollection collection, HttpFileCollectionBase files, string userHostAddress) { var manager = FormsManager.GetManager(); var form = manager.GetForm(this.FormId); var formEntry = new FormEntryDTO(form); var formSubmition = new FormsSubmitionHelper(); if (!this.ValidateFormSubmissionRestrictions(formSubmition, formEntry)) { return(SubmitStatus.RestrictionViolation); } if (!this.RaiseFormValidatingEvent(formEntry) || !this.IsValidForm(form, collection, files, manager)) { return(SubmitStatus.InvalidEntry); } var formFields = new HashSet <string>(form.Controls.Select(this.FormFieldName).Where((f) => !string.IsNullOrEmpty(f))); var postedFiles = new Dictionary <string, List <FormHttpPostedFile> >(); if (files != null) { for (int i = 0; i < files.AllKeys.Length; i++) { if (formFields.Contains(files.AllKeys[i])) { postedFiles[files.AllKeys[i]] = files.GetMultiple(files.AllKeys[i]).Where(f => !f.FileName.IsNullOrEmpty()).Select(f => new FormHttpPostedFile() { FileName = f.FileName, ContentLength = f.ContentLength, ContentType = f.ContentType, InputStream = f.InputStream }).ToList(); } } } var formData = new Dictionary <string, object>(collection.Count); for (int i = 0; i < collection.Count; i++) { if (formFields.Contains(collection.Keys[i])) { formData.Add(collection.Keys[i], collection[collection.Keys[i]]); } } formEntry.PostedData.FormsData = formData; formEntry.PostedData.Files = postedFiles; if (this.RaiseFormSavingEvent(formEntry)) { formSubmition.Save(formEntry); this.RaiseFormSavedEvent(formEntry); return(SubmitStatus.Success); } else { return(SubmitStatus.RestrictionViolation); } }
/// <inheritDoc/> public virtual SubmitStatus TrySubmitForm(FormCollection collection, HttpFileCollectionBase files, string userHostAddress) { var manager = FormsManager.GetManager(); var formIdString = collection[FormIdName]; Guid formId; if (!string.IsNullOrWhiteSpace(formIdString) && Guid.TryParse(formIdString, out formId)) { this.FormId = formId; } var form = manager.GetForm(this.FormId); var formEntry = new FormEntryDTO(form); var formSubmition = new FormsSubmitionHelper(); if (!this.ValidateFormSubmissionRestrictions(formSubmition, formEntry)) { return(SubmitStatus.RestrictionViolation); } Dictionary <string, IFormFieldController <IFormFieldModel> > currentFormFields; List <IFormElementController <IFormElementModel> > formElements; this.LoadFormControls(form, collection, files, manager, out currentFormFields, out formElements); Dictionary <IFormFieldController <IFormFieldModel>, bool> fieldControls; if (!this.RaiseFormValidatingEvent(formEntry, currentFormFields, collection, files) || !this.IsValidForm(form, collection, files, currentFormFields, formElements, out fieldControls)) { return(SubmitStatus.InvalidEntry); } var formFields = fieldControls.Select(p => new { FieldName = this.FormFieldName(p.Key), CanSave = p.Value }).Where(field => !string.IsNullOrEmpty(field.FieldName)); var postedFiles = new Dictionary <string, List <FormHttpPostedFile> >(); if (files != null) { for (int i = 0; i < files.AllKeys.Length; i++) { if (formFields.FirstOrDefault(p => p.FieldName == files.AllKeys[i]) != null) { postedFiles[files.AllKeys[i]] = files.GetMultiple(files.AllKeys[i]).Where(f => !f.FileName.IsNullOrEmpty()).Select(f => new FormHttpPostedFile() { FileName = f.FileName, ContentLength = f.ContentLength, ContentType = f.ContentType, InputStream = f.InputStream }).ToList(); } } } var formData = new Dictionary <string, object>(collection.Count); for (int i = 0; i < collection.Count; i++) { var formField = formFields.FirstOrDefault(p => p.FieldName == collection.Keys[i]); if (formField != null) { formData.Add(collection.Keys[i], formField.CanSave ? collection[collection.Keys[i]] : string.Empty); } } formEntry.PostedData.FormsData = formData; formEntry.PostedData.Files = postedFiles; var formRules = new List <FormRule>(); if (!string.IsNullOrWhiteSpace(form.Rules)) { formRules = JsonConvert.DeserializeObject <List <FormRule> >(form.Rules); } formEntry.NotificationEmails = this.GetSendNotificationEmails(formRules, collection); this.UpdateCustomConfirmationMode(formRules, collection); this.SetConnectorSettingsToContext(); if (this.RaiseFormSavingEvent(formEntry)) { formSubmition.Save(formEntry); this.RaiseFormSavedEvent(formEntry); this.InvalidateCaptchas(); return(SubmitStatus.Success); } else { return(SubmitStatus.RestrictionViolation); } }
/// <summary> /// Raises the form validating event. /// </summary> /// <param name="formEntry">The form entry.</param> /// <returns>Whether validation succeeded.</returns> protected virtual bool RaiseFormValidatingEvent(FormEntryDTO formEntry) { var formEvent = this.eventFactory.GetFormValidatingEvent(formEntry); return !this.ValidationEventFailed(formEvent); }
/// <summary> /// Raises the form saving event. /// </summary> /// <param name="formEntry">The form entry.</param> /// <returns>Whether processing should continue.</returns> protected virtual bool RaiseFormSavingEvent(FormEntryDTO formEntry) { var formEvent = this.eventFactory.GetFormSavingEvent(formEntry); return !this.IsEventCancelled(formEvent); }
/// <summary> /// Raises the form saved event. /// </summary> /// <param name="formEntry">The form entry.</param> protected virtual void RaiseFormSavedEvent(FormEntryDTO formEntry) { var formEvent = this.eventFactory.GetFormSavedEvent(formEntry); EventHub.Raise(formEvent); }
/// <summary> /// Raises the before form action event. /// </summary> public virtual bool RaiseBeforeFormActionEvent() { var manager = FormsManager.GetManager(); var form = manager.GetForm(this.FormId); var formEntry = new FormEntryDTO(form); var formEvent = this.eventFactory.GetBeforeFormActionEvent(formEntry); return !this.IsEventCancelled(formEvent); }