Class Form


@Marshalled(typeName="form") public class Form extends HtmlElementMixed<Form>
DTO for an HTML <form> element.

The form element represents a document section containing interactive controls for submitting information to a web server. It groups form controls together and defines how the data should be submitted, including the target URL, HTTP method, and encoding type.

Examples:

// Simple contact form Form form1 = form() .action("/contact") .method("post") .children( input("text").name("name").placeholder("Your Name"), input("email").name("email").placeholder("Your Email"), textarea().name("message").placeholder("Your Message"), button().type("submit").text("Send Message") ); // File upload form Form form2 = form() .action("/upload") .method("post") .enctype("multipart/form-data") .children( input("file").name("file").accept("image/*"), button().type("submit").text("Upload") ); // Form with validation Form form3 = form() .action("/register") .method("post") .novalidate(false) .children( input("email").name("email").required(true), input("password").name("password").required(true), button().type("submit").text("Register") );

The following convenience methods are provided for constructing instances of this bean:

See Also:
  • Constructor Details

    • Form

      public Form()
      Creates an empty Form element.
    • Form

      public Form(String action)
      Creates a Form element with the specified action(String) attribute.
      Parameters:
      action - The action(String) attribute. Can be null, in which case the attribute is stored with a null value (not removed).
    • Form

      public Form(String action, Object... children)
      Creates an Form element with the specified action(String) attribute and child nodes.
      Parameters:
      action - The action(String) attribute. Can be null, in which case the attribute is stored with a null value (not removed).
      children - The child nodes. Must not be null.
  • Method Details

    • acceptcharset

      public Form acceptcharset(String value)
      accept-charset attribute.

      Specifies the character encodings that are accepted for form submission. Multiple encodings can be specified as a space-separated list.

      Common values:

      • "UTF-8" - Unicode UTF-8 encoding (default)
      • "ISO-8859-1" - Latin-1 encoding
      • "UTF-8 ISO-8859-1" - Multiple encodings
      Parameters:
      value - The character encodings accepted for form submission. Can be null to unset the attribute.
      Returns:
      This object.
    • action

      public Form action(String value)
      action attribute.

      URL to use for form submission.

      The value can be of any of the following types: URI, URL, String. Strings must be valid URIs.

      URIs defined by UriResolver can be used for values.

      Parameters:
      value - The new value for this attribute. Can be null, in which case the attribute is stored with a null value (not removed).
      Returns:
      This object.
    • autocomplete

      public Form autocomplete(String value)
      autocomplete attribute.

      Sets the default autocomplete behavior for all form controls within this form. Individual controls can override this setting.

      Possible values:

      • "on" - Allow autocomplete (default)
      • "off" - Disable autocomplete
      Parameters:
      value - The default autocomplete behavior for form controls. Can be null to unset the attribute.
      Returns:
      This object.
    • enctype

      public Form enctype(String value)
      enctype attribute.

      Specifies how form data should be encoded when submitted to the server.

      Possible values:

      • "application/x-www-form-urlencoded" - Default encoding (default)
      • "multipart/form-data" - Used for file uploads
      • "text/plain" - Plain text encoding
      Parameters:
      value - The encoding type for form data submission. Can be null to unset the attribute.
      Returns:
      This object.
    • method

      public Form method(String value)
      method attribute.

      Specifies the HTTP method to use when submitting the form.

      Possible values:

      • "get" - Form data is sent as URL parameters (default)
      • "post" - Form data is sent in the request body
      • "dialog" - Used for forms within dialog elements
      Parameters:
      value - The HTTP method for form submission. Can be null to unset the attribute.
      Returns:
      This object.
    • name

      public Form name(String value)
      name attribute.

      Specifies the name of the form. This name can be used to access the form via the document.forms API and for form submission.

      The name should be unique within the document and should not contain spaces or special characters.

      Parameters:
      value - The name of the form for API access and submission. Can be null to unset the attribute.
      Returns:
      This object.
    • novalidate

      public Form novalidate(Boolean value)
      novalidate attribute.

      Disables form validation, allowing the form to be submitted even if validation fails.

      Parameters:
      value - If true, disables form validation. Can be null to unset the attribute.
      Returns:
      This object.
    • target

      public Form target(String value)
      target attribute.

      Specifies where to display the response after form submission.

      Possible values:

      • "_self" - Load in the same frame (default)
      • "_blank" - Load in a new window or tab
      • "_parent" - Load in the parent frame
      • "_top" - Load in the full body of the window
      • Frame name - Load in the named frame
      Parameters:
      value - Where to display the form submission response. Can be null to unset the attribute.
      Returns:
      This object.