Curriculum
Course: HTML Basic
Login

Curriculum

HTML Basic

HTML Introduction

0/1

HTML Editors

0/1

HTML Elements

0/1

HTML Attributes

0/1

HTML Headings

0/1

HTML Paragraphs

0/1

HTML Styles

0/1

HTML Formatting

0/1

HTML Quotation

0/1

HTML Comments

0/1

HTML Colors

0/1

HTML Favicon

0/1

HTML Page Title

0/1

HTML Block and Inline

0/1

HTML Iframes

0/1

HTML Java Script

0/1

HTML File Paths

0/1

HTML - The Head Element

0/1

HTML Style Guide

0/1

HTML Entities

0/1

HTML Symbols

0/1
Text lesson

Input Form Attribute

This chapter delineates the various attributes related to the form* functionality within the HTML <input> element.

The form Attribute

The “form” attribute of the <input> element denotes the specific form to which it pertains.

It requires a value corresponding to the “id” attribute of the relevant <form> element.

Example

An input field that resides external to the HTML form structure but remains associated with the form.

<form action=”/action_page.php” id=”form1″>
  <label for=”fname”>First name:</label>
  <input type=”text” id=”fname” name=”fname”><br><br>
  <input type=”submit” value=”Submit”>
</form>

<label for=”lname”>Last name:</label>
<input type=”text” id=”lname” name=”lname” form=”form1″>

The formaction Attribute

The “formaction” attribute of the input element designates the URL of the file responsible for processing input upon form submission.

Important to note, this attribute supersedes the “action” attribute of the <form> element.

The “formaction” attribute is compatible with the following input types: submit and image.

Example

An HTML form featuring two submit buttons, each triggering distinct actions.

<form action=”/action_page.php”>
  <label for=”fname”>First name:</label>
  <input type=”text” id=”fname” name=”fname”><br><br>
  <label for=”lname”>Last name:</label>
  <input type=”text” id=”lname” name=”lname”><br><br>
  <input type=”submit” value=”Submit”>
  <input type=”submit” formaction=”/action_page2.php” value=”Submit as Admin”>
</form>

The formenctype Attribute

The “formenctype” attribute of the input element determines the encoding method for form data upon submission, applicable only for forms using the “post” method.

It’s essential to note that this attribute takes precedence over the “enctype” attribute of the <form> element.

The “formenctype” attribute is compatible with the following input types: submit and image.

Example

A form featuring two submit buttons: one sends form-data using the default encoding, while the other sends the form-data encoded as “multipart/form-data”.

<form action=”/action_page_binary.asp” method=”post”>
  <label for=”fname”>First name:</label>
  <input type=”text” id=”fname” name=”fname”><br><br>
  <input type=”submit” value=”Submit”>
  <input type=”submit” formenctype=”multipart/form-data”
  value=”Submit as Multipart/form-data”
>

</form>

The formmethod Attribute

The “formmethod” attribute of the input element specifies the HTTP method for transmitting form-data to the action URL.

Crucially, this attribute takes precedence over the “method” attribute of the <form> element.

The “formmethod” attribute is compatible with the following input types: submit and image.

Form data can be dispatched either as URL variables (method=”get”) or as an HTTP post transaction (method=”post”).

Points regarding the “get” method:

  • This approach attaches the form-data to the URL as name/value pairs,
  • a method often employed when users wish to bookmark the outcome of their form submission.
  • It’s important to acknowledge that there’s a limit to the amount of data that can be accommodated in a URL (which varies across browsers), hence, complete transfer of all form-data isn’t guaranteed.
  • Under no circumstances should the “get” method be used to transmit sensitive information! Doing so would expose passwords or other confidential data in the browser’s address bar.

Points regarding the “post” method:

  • This approach transmits form-data via an HTTP post transaction.
  • Unlike “get” submissions, form submissions with the “post” method cannot be bookmarked.
  • The “post” method is notably more robust and secure than “get”. Additionally, it doesn’t impose size limitations.

Example

A form featuring two submit buttons: one transmits the form-data using the “get” method, while the other transmits it using the “post” method.

<form action=”/action_page.php” method=”get”>
  <label for=”fname”>First name:</label>
  <input type=”text” id=”fname” name=”fname”><br><br>
  <label for=”lname”>Last name:</label>
  <input type=”text” id=”lname” name=”lname”><br><br>
  <input type=”submit” value=”Submit using GET”>
  <input type=”submit” formmethod=”post” value=”Submit using POST”>
</form>

The formtarget Attribute

The “formtarget” attribute of the input element designates a name or keyword dictating where the response received after form submission should be displayed.

Note: It’s essential to note that this attribute supersedes the “target” attribute of the <form> element.

The “formtarget” attribute is compatible with the following input types: submit and image.

Example

A form featuring two submit buttons, each directing responses to different target windows.

<form action=”/action_page.php”>
  <label for=”fname”>First name:</label>
  <input type=”text” id=”fname” name=”fname”><br><br>
  <label for=”lname”>Last name:</label>
  <input type=”text” id=”lname” name=”lname”><br><br>
  <input type=”submit” value=”Submit”>
  <input type=”submit” formtarget=”_blank” value=”Submit to a new window/tab”>
</form>

The formnovalidate Attribute

The “formnovalidate” attribute of the input element indicates that an <input> element should not undergo validation upon submission.

It’s important to note that this attribute takes precedence over the “novalidate” attribute of the <form> element.

The “formnovalidate” attribute is applicable only to input types: submit.

Example

A form containing two submit buttons, one subjected to validation and the other not.

<form action=”/action_page.php”>
  <label for=”email”>Enter your email:</label>
  <input type=”email” id=”email” name=”email”><br><br>
  <input type=”submit” value=”Submit”>
  <input type=”submit” formnovalidate=”formnovalidate”
  value=”Submit without validation”
>

</form>

The novalidate Attribute

The “novalidate” attribute belongs to the <form> element.

When included, “novalidate” indicates that all form-data should bypass validation upon submission.

Example

Indicate that validation of form-data should be disabled upon submission.

<form action=”/action_page.php” novalidate>
  <label for=”email”>Enter your email:</label>
  <input type=”email” id=”email” name=”email”><br><br>
  <input type=”submit” value=”Submit”>
</form>

 

Click to Learn