Html input data action

HTML Form Attributes

This chapter describes the different attributes for the HTML element.

The Action Attribute

The action attribute defines the action to be performed when the form is submitted.

Usually, the form data is sent to a file on the server when the user clicks on the submit button.

In the example below, the form data is sent to a file called «action_page.php». This file contains a server-side script that handles the form data:

Example

On submit, send form data to «action_page.php»:

Tip: If the action attribute is omitted, the action is set to the current page.

The Target Attribute

The target attribute specifies where to display the response that is received after submitting the form.

The target attribute can have one of the following values:

Value Description
_blank The response is displayed in a new window or tab
_self The response is displayed in the current window
_parent The response is displayed in the parent frame
_top The response is displayed in the full body of the window
framename The response is displayed in a named iframe
Читайте также:  Автоматическое создание таблиц php

The default value is _self which means that the response will open in the current window.

Example

Here, the submitted result will open in a new browser tab:

The Method Attribute

The method attribute specifies the HTTP method to be used when submitting the form data.

The form-data can be sent as URL variables (with method=»get» ) or as HTTP post transaction (with method=»post» ).

The default HTTP method when submitting form data is GET.

Example

This example uses the GET method when submitting the form data:

Example

This example uses the POST method when submitting the form data:

  • Appends the form data to the URL, in name/value pairs
  • NEVER use GET to send sensitive data! (the submitted form data is visible in the URL!)
  • The length of a URL is limited (2048 characters)
  • Useful for form submissions where a user wants to bookmark the result
  • GET is good for non-secure data, like query strings in Google
  • Appends the form data inside the body of the HTTP request (the submitted form data is not shown in the URL)
  • POST has no size limitations, and can be used to send large amounts of data.
  • Form submissions with POST cannot be bookmarked

Tip: Always use POST if the form data contains sensitive or personal information!

The Autocomplete Attribute

The autocomplete attribute specifies whether a form should have autocomplete on or off.

When autocomplete is on, the browser automatically complete values based on values that the user has entered before.

Example

A form with autocomplete on:

The Novalidate Attribute

The novalidate attribute is a boolean attribute.

When present, it specifies that the form-data (input) should not be validated when submitted.

Example

A form with a novalidate attribute:

HTML Exercises

List of All Attributes

Attribute Description
accept-charset Specifies the character encodings used for form submission
action Specifies where to send the form-data when a form is submitted
autocomplete Specifies whether a form should have autocomplete on or off
enctype Specifies how the form-data should be encoded when submitting it to the server (only for method=»post»)
method Specifies the HTTP method to use when sending form-data
name Specifies the name of the form
novalidate Specifies that the form should not be validated when submitted
rel Specifies the relationship between a linked resource and the current document
target Specifies where to display the response that is received after submitting the form

Источник

HTML action Attribute

On submit, send the form-data to a file named «action_page.php» (to process the input):

Definition and Usage

The action attribute specifies where to send the form-data when a form is submitted.

Browser Support

Syntax

Attribute Values

  • An absolute URL — points to another web site (like action=»http://www.example.com/example.htm»)
  • A relative URL — points to a file within a web site (like action=»example.htm»)

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

HTML Input form* Attributes

This chapter describes the different form* attributes for the HTML element.

The form Attribute

The input form attribute specifies the form the element belongs to.

The value of this attribute must be equal to the id attribute of the element it belongs to.

Example

An input field located outside of the HTML form (but still a part of the form):

The formaction Attribute

The input formaction attribute specifies the URL of the file that will process the input when the form is submitted.

Note: This attribute overrides the action attribute of the element.

The formaction attribute works with the following input types: submit and image.

Example

An HTML form with two submit buttons, with different actions:

The formenctype Attribute

The input formenctype attribute specifies how the form-data should be encoded when submitted (only for forms with method=»post»).

Note: This attribute overrides the enctype attribute of the element.

The formenctype attribute works with the following input types: submit and image.

Example

A form with two submit buttons. The first sends the form-data with default encoding, the second sends the form-data encoded as «multipart/form-data»:

The formmethod Attribute

The input formmethod attribute defines the HTTP method for sending form-data to the action URL.

Note: This attribute overrides the method attribute of the element.

The formmethod attribute works with the following input types: submit and image.

The form-data can be sent as URL variables (method=»get») or as an HTTP post transaction (method=»post»).

Notes on the «get» method:

  • This method appends the form-data to the URL in name/value pairs
  • This method is useful for form submissions where a user want to bookmark the result
  • There is a limit to how much data you can place in a URL (varies between browsers), therefore, you cannot be sure that all of the form-data will be correctly transferred
  • Never use the «get» method to pass sensitive information! (password or other sensitive information will be visible in the browser’s address bar)

Notes on the «post» method:

  • This method sends the form-data as an HTTP post transaction
  • Form submissions with the «post» method cannot be bookmarked
  • The «post» method is more robust and secure than «get», and «post» does not have size limitations

Example

A form with two submit buttons. The first sends the form-data with method=»get». The second sends the form-data with method=»post»:

The formtarget Attribute

The input formtarget attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.

Note: This attribute overrides the target attribute of the element.

The formtarget attribute works with the following input types: submit and image.

Example

A form with two submit buttons, with different target windows:

The formnovalidate Attribute

The input formnovalidate attribute specifies that an element should not be validated when submitted.

Note: This attribute overrides the novalidate attribute of the element.

The formnovalidate attribute works with the following input types: submit.

Example

A form with two submit buttons (with and without validation):

The novalidate Attribute

The novalidate attribute is a attribute.

When present, novalidate specifies that all of the form-data should not be validated when submitted.

Example

Specify that no form-data should be validated on submit:

HTML Form and Input Elements

For a complete list of all available HTML tags, visit our HTML Tag Reference.

Источник

Оцените статью