pub struct Form;Expand description
The <form> element - represents a document section containing interactive controls for submitting information.
§Purpose
The <form> element represents a collection of form-associated elements for gathering
user input and submitting data to a server. It provides the context for form controls,
handles submission, and defines how data should be encoded and transmitted.
§Content Categories
- Flow Content
- Palpable Content
§Permitted Content Model
- Flow content (but no nested
<form>elements)
§Common Use Cases
- User registration and login forms
- Search interfaces
- Contact and feedback forms
- E-commerce checkout processes
- Survey and questionnaire forms
§Key Attributes
action: URL where form data is sentmethod: HTTP method for submission (“get” or “post”)enctype: Encoding type for form data (“application/x-www-form-urlencoded”, “multipart/form-data”, “text/plain”)name: Name of the formtarget: Browsing context for response (“_self”, “_blank”, “_parent”, “_top”)novalidate: Disable built-in validationautocomplete: Enable/disable autocomplete (“on” or “off”)accept-charset: Character encodings for submission
§Example
<!-- Basic login form -->
<form action="/login" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Log In</button>
</form>
<!-- Search form with GET -->
<form action="/search" method="get" role="search">
<label for="q">Search:</label>
<input type="search" id="q" name="q" placeholder="Enter search terms">
<button type="submit">Search</button>
</form>
<!-- File upload form -->
<form action="/upload" method="post" enctype="multipart/form-data">
<label for="file">Choose file:</label>
<input type="file" id="file" name="file" required>
<button type="submit">Upload</button>
</form>
<!-- Form with validation disabled -->
<form action="/submit" method="post" novalidate>
<input type="email" name="email">
<button type="submit">Submit</button>
</form>
<!-- Form targeting new window -->
<form action="/external" method="post" target="_blank">
<input type="text" name="data">
<button type="submit">Open in New Tab</button>
</form>§Accessibility
- Use
<label>elements for all form controls - Group related fields with
<fieldset>and<legend> - Provide clear error messages near relevant fields
- Ensure logical tab order through form fields
- Use
autocompleteattributes appropriately - Add
aria-describedbyfor additional instructions
§WHATWG Specification
Trait Implementations§
Source§impl HtmlElement for Form
impl HtmlElement for Form
impl<T: FlowContent> CanContain<T> for Form
impl FlowContent for Form
impl PalpableContent for Form
Auto Trait Implementations§
impl Freeze for Form
impl RefUnwindSafe for Form
impl Send for Form
impl Sync for Form
impl Unpin for Form
impl UnwindSafe for Form
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more