Class Form<T extends Form<T>>


public class Form<T extends Form<T>> extends StyledContainerElement<T>
Represents the HTML <form> element for traditional browser-based form submission.

The Form class provides a pure HTML form wrapper for collecting user input and submitting data to a server via standard browser mechanisms (GET/POST). When submitted, the browser navigates to the action URL with the form data.

For server-side form handling within the Oorian framework with built-in validation support, use OorianForm instead.

Features:

  • Configurable form action URL and HTTP method (GET/POST)
  • Support for form encoding types (multipart, URL-encoded, plain text)
  • Browser validation control with novalidate attribute
  • Auto-completion settings for browser assistance
  • Target window specification for form submission
  • Character set encoding configuration

Usage Example:


 // Create a form that posts to an external endpoint
 Form form = new Form();
 form.setAction("/api/register");
 form.setMethod(FormMethod.POST);
 form.setAutoComplete(true);

 // Add form fields
 TextInput username = new TextInput("username");
 PasswordInput password = new PasswordInput("password");
 Button submitBtn = new Button("Register");
 submitBtn.setType(ButtonType.SUBMIT);

 form.addElement(username);
 form.addElement(password);
 form.addElement(submitBtn);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Form

      public Form()
      Constructs a new form element.
  • Method Details

    • setAccept

      @Deprecated public final T setAccept(String mimetypes)
      Deprecated.
      Use the accept attribute on individual <input> elements instead.
      Sets the accepted content types for file inputs within this form.
      Overrides:
      setAccept in class Element<T extends Form<T>>
      Parameters:
      mimetypes - comma-separated list of accepted MIME types
      Returns:
      this element for method chaining
    • setAcceptCharset

      public final T setAcceptCharset(String charset)
      Sets the character encodings the server accepts for form submission.
      Parameters:
      charset - space-separated list of character encodings (e.g., "UTF-8")
      Returns:
      this element for method chaining
    • setAction

      public final T setAction(String action)
      Sets the URL where the form data will be submitted.

      If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended.

      Parameters:
      action - The form action URL.
      Returns:
      this element for method chaining
    • setAutoComplete

      public final T setAutoComplete(boolean on)
      Enables or disables browser autocomplete for the form.
      Parameters:
      on - true to enable autocomplete, false to disable.
      Returns:
      this element for method chaining
    • setEncType

      public final T setEncType(FormEncoding encoding)
      Sets the encoding type for form data submission using the FormEncoding enum.
      Parameters:
      encoding - the form encoding type
      Returns:
      this element for method chaining
    • setEncType

      public final T setEncType(String encoding)
      Sets the encoding type for form data submission.

      Common values include "application/x-www-form-urlencoded" (default), "multipart/form-data" (for file uploads), and "text/plain".

      Parameters:
      encoding - the MIME type for form encoding
      Returns:
      this element for method chaining
    • setMethod

      public final T setMethod(FormMethod method)
      Sets the HTTP method for form submission using the FormMethod enum.
      Parameters:
      method - the HTTP method (GET or POST)
      Returns:
      this element for method chaining
    • setMethod

      public final T setMethod(String method)
      Sets the HTTP method for form submission.
      Parameters:
      method - the HTTP method as a string (e.g., "get", "post", "dialog")
      Returns:
      this element for method chaining
    • setName

      public final T setName(String name)
      Sets the name of this form element.

      The name is used to identify the form in scripts and as a key for form data.

      Parameters:
      name - The name of the form.
      Returns:
      This element for method chaining.
    • setRel

      public final T setRel(String rel)
      Sets the rel attribute.

      Specifies the relationship between the current document and the form action URL. Common values include "noopener", "noreferrer", and "external".

      Parameters:
      rel - The relationship of the form action.
      Returns:
      This element for method chaining.
    • setNoValidate

      public final T setNoValidate(boolean flag)
      Sets whether the form should bypass validation on submission.

      When true, the form will not be validated before submitting. This is useful for "save draft" functionality where incomplete data should be accepted.

      Parameters:
      flag - true to disable form validation, false to enable it
      Returns:
      this element for method chaining
    • setTarget

      public final T setTarget(Target target)
      Sets the target attribute using the Target enum.
      Parameters:
      target - The target browsing context for form submission.
      Returns:
      This element for method chaining.
    • setTarget

      public final T setTarget(String target)
      Sets the target attribute.

      Specifies the browsing context in which to display the form submission response. Values include "_self" (same context), "_blank" (new tab/window), "_parent" (parent context), and "_top" (top-level context).

      Parameters:
      target - The browsing context for form submission.
      Returns:
      This element for method chaining.
    • setOnSubmit

      public void setOnSubmit(String value)
      Sets the JavaScript onsubmit event handler for this element.

      Fires when a form is submitted.

      Parameters:
      value - The JavaScript code to execute on form submission.
    • setOnReset

      public void setOnReset(String value)
      Sets the JavaScript onreset event handler for this element.

      Fires when a form is reset.

      Parameters:
      value - The JavaScript code to execute on form reset.
    • submit

      public void submit()
      Programmatically submits the form.