Esempio n. 1
0
        public string GetDefault(IHtmlHelper helper, Webpage webpage, FormSubmittedStatus submittedStatus)
        {
            if (webpage == null)
            {
                return(string.Empty);
            }

            var formProperties = webpage.FormProperties.OrderBy(x => x.DisplayOrder);

            if (!formProperties.Any())
            {
                return(string.Empty);
            }

            var form = GetForm(webpage);

            foreach (var property in formProperties)
            {
                string elementHtml            = string.Empty;
                IFormElementRenderer renderer = _elementRendererManager.GetElementRenderer(property);
                elementHtml += _labelRenderer.AppendLabel(property);
                var existingValue = submittedStatus.Data[property.Name];
                elementHtml += renderer.AppendElement(property, existingValue, _siteSettings.FormRendererType)
                               .ToString(renderer.IsSelfClosing
                                                        ? TagRenderMode.SelfClosing
                                                        : TagRenderMode.Normal);
                elementHtml += _validationMessaageRenderer.AppendRequiredMessage(property);
                var elementContainer = _elementRendererManager.GetElementContainer(_siteSettings.FormRendererType, property);
                if (elementContainer != null)
                {
                    elementContainer.InnerHtml += elementHtml;
                    form.InnerHtml             += elementContainer;
                }
                else
                {
                    form.InnerHtml += elementHtml;
                }
            }

            form.InnerHtml += helper.RenderRecaptcha().ToString();

            var div = new TagBuilder("div");

            div.InnerHtml  += GetSubmitButton(webpage).ToString(TagRenderMode.SelfClosing);
            form.InnerHtml += div;

            if (submittedStatus.Submitted)
            {
                form.InnerHtml += new TagBuilder("br");
                form.InnerHtml += _submittedMessageRenderer.AppendSubmittedMessage(webpage, submittedStatus);
            }

            if (_siteSettings.HasHoneyPot)
            {
                form.InnerHtml += _siteSettings.GetHoneypot();
            }

            return(form.ToString());
        }
Esempio n. 2
0
        private MatchEvaluator AddElement(IList <FormProperty> formProperties, FormSubmittedStatus submittedStatus)
        {
            return(match =>
            {
                FormProperty formProperty =
                    formProperties.FirstOrDefault(
                        property => property.Name.Equals(match.Groups[1].Value, StringComparison.OrdinalIgnoreCase));
                if (formProperty == null)
                {
                    return string.Empty;
                }
                string existingValue = submittedStatus.Data[formProperty.Name];

                IFormElementRenderer renderer = _elementRendererManager.GetElementRenderer(formProperty);

                return
                renderer.AppendElement(formProperty, existingValue, _siteSettings.FormRendererType)
                .ToString(renderer.IsSelfClosing
                                                     ? TagRenderMode.SelfClosing
                                                     : TagRenderMode.Normal);
            });
        }