/// <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);
            }
        }
Beispiel #2
0
        /// <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;
        }
Beispiel #3
0
        /// <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);
            }
        }