AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.3.7" />

.NET API 586,752 bytes

 HTMLFormElement

public sealed class HTMLFormElement : HTMLElement
Represents the form element.
using AngleSharp.DOM.Collections; using System.Collections.Generic; namespace AngleSharp.DOM.Html { [DOM("HTMLFormElement")] public sealed class HTMLFormElement : HTMLElement { private HTMLLiveCollection<HTMLFormControlElement> _elements; private HTMLFormControlsCollection _formControls; public Element this[int index] { get { return _elements[index]; } } public object this[string name] { get { return _elements[name]; } } [DOM("name")] public string Name { get { return GetAttribute("name"); } set { SetAttribute("name", value); } } [DOM("length")] public int Length { get { return _elements.Length; } } [DOM("elements")] public HTMLFormControlsCollection Elements { get { return _formControls; } } [DOM("acceptCharset")] public string AcceptCharset { get { return GetAttribute("acceptCharset"); } set { SetAttribute("acceptCharset", value); } } [DOM("action")] public string Action { get { return GetAttribute("action"); } set { SetAttribute("action", value); } } [DOM("autocomplete")] public PowerState Autocomplete { get { return Element.ToEnum(GetAttribute("autocomplete"), PowerState.On); } set { SetAttribute("autocomplete", value.ToString()); } } [DOM("enctype")] public string Enctype { get { return CheckEncType(GetAttribute("enctype")); } set { SetAttribute("enctype", CheckEncType(value)); } } [DOM("encoding")] public string Encoding { get { return Enctype; } set { Enctype = value; } } [DOM("method")] public HttpMethod Method { get { return Element.ToEnum(GetAttribute("method"), HttpMethod.GET); } set { SetAttribute("method", value.ToString()); } } [DOM("noValidate")] public bool NoValidate { get { return GetAttribute("novalidate") != null; } set { SetAttribute("novalidate", value ? string.Empty : null); } } [DOM("target")] public string Target { get { return GetAttribute("target"); } set { SetAttribute("target", value); } } protected internal override bool IsSpecial => true; internal HTMLFormElement() { _name = "form"; _elements = new HTMLLiveCollection<HTMLFormControlElement>(this, true); _formControls = new HTMLFormControlsCollection(_elements); } [DOM("submit")] public HTMLFormElement Submit() { SubmitForm(this, true); return this; } [DOM("reset")] public HTMLFormElement Reset() { foreach (HTMLFormControlElement element in _elements.Elements) { element.Reset(); } return this; } [DOM("checkValidity")] public bool CheckValidity() { foreach (HTMLFormControlElement element in _elements.Elements) { if (!element.CheckValidity()) return false; } return true; } private void SubmitForm(HTMLElement from, bool submittedFromSubmitMethod) { Document ownerDocument = base.OwnerDocument; new object(); if (!submittedFromSubmitMethod && from.Attributes["formnovalidate"] == null && NoValidate && !CheckValidity()) FireSimpleEvent("invalid"); else { ConstructDataSet(null); string text = Action; if (string.IsNullOrEmpty(text)) text = ownerDocument.DocumentURI; if (!Location.IsAbsolute(text)) text = Location.MakeAbsolute(from.BaseURI, text); Location location = new Location(text); string protocol; if ((protocol = location.Protocol) != null) { if (!(protocol == "http:") && !(protocol == "https:")) { if (!(protocol == "ftp:") && !(protocol == "javascript:")) { if (!(protocol == "data:")) { if (protocol == "mailto:") { if (Method == HttpMethod.GET) MailWithHeaders(); else if (Method == HttpMethod.POST) { MailAsBody(); } } } else if (Method == HttpMethod.GET) { GetActionUrl(); } else if (Method == HttpMethod.POST) { PostToData(); } } else GetActionUrl(); } else if (Method == HttpMethod.GET) { MutateActionUrl(); } else if (Method == HttpMethod.POST) { SubmitAsEntityBody(); } } } } private void PostToData() { } private void MailWithHeaders() { } private void MailAsBody() { } private void GetActionUrl() { } private void SubmitAsEntityBody() { } private void MutateActionUrl() { } private FormDataSet ConstructDataSet(HTMLElement submitter = null) { FormDataSet formDataSet = new FormDataSet(); IEnumerable<HTMLFormControlElement> elements = _elements.Elements; foreach (HTMLFormControlElement item in elements) { if (!(item.ParentElement is HTMLDataListElement) && !item.Disabled) item.ConstructDataSet(formDataSet, submitter); } return formDataSet; } private string CheckEncType(string encType) { if (encType == MimeTypes.Plain || encType == MimeTypes.MultipartForm) return encType; return MimeTypes.StandardForm; } } }