What is action attribute in html

: The Form element

The HTML element represents a document section containing interactive controls for submitting information.

Try it

It is possible to use the :valid and :invalid CSS pseudo-classes to style a element based on whether the elements inside the form are valid.

Attributes

This element includes the global attributes.

Comma-separated content types the server accepts.

Note: This attribute has been deprecated and should not be used. Instead, use the accept attribute on elements.

Space-separated character encodings the server accepts. The browser uses them in the order in which they are listed. The default value means the same encoding as the page. (In previous versions of HTML, character encodings could also be delimited by commas.)

A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized. autocapitalize attributes on a form elements override it on . Possible values:

  • none : No automatic capitalization.
  • sentences (default): Capitalize the first letter of each sentence.
  • words : Capitalize the first letter of each word.
  • characters : Capitalize all characters — that is, uppercase.

Indicates whether input elements can by default have their values automatically completed by the browser. autocomplete attributes on form elements override it on . Possible values:

  • off : The browser may not automatically complete entries. (Browsers tend to ignore this for suspected login forms; see The autocomplete attribute and login fields.)
  • on : The browser may automatically complete entries.

The name of the form. The value must not be the empty string, and must be unique among the form elements in the forms collection that it is in, if any.

Controls the annotations and what kinds of links the form creates. Annotations include external , nofollow , opener , noopener , and noreferrer . Link types include help , prev , next , search , and license . The rel value is a space-separated list of these enumerated values.

Attributes for form submission

The following attributes control behavior during form submission.

The URL that processes the form submission. This value can be overridden by a formaction attribute on a , , or element. This attribute is ignored when method=»dialog» is set.

If the value of the method attribute is post , enctype is the MIME type of the form submission. Possible values:

  • application/x-www-form-urlencoded : The default value.
  • multipart/form-data : Use this if the form contains elements with type=file .
  • text/plain : Useful for debugging purposes.
Читайте также:  Typescript получить значение поля

This value can be overridden by formenctype attributes on , , or elements.

The HTTP method to submit the form with. The only allowed methods/values are (case insensitive):

  • post : The POST method; form data sent as the request body.
  • get (default): The GET ; form data appended to the action URL with a ? separator. Use this method when the form has no side effects.
  • dialog : When the form is inside a , closes the dialog and causes a submit event to be fired on submission, without submitting data or clearing the form.

This value is overridden by formmethod attributes on , , or elements.

This Boolean attribute indicates that the form shouldn’t be validated when submitted. If this attribute is not set (and therefore the form is validated), it can be overridden by a formnovalidate attribute on a , , or element belonging to the form.

Indicates where to display the response after submitting the form. It is a name/keyword for a browsing context (for example, tab, window, or iframe). The following keywords have special meanings:

  • _self (default): Load into the same browsing context as the current one.
  • _blank : Load into a new unnamed browsing context. This provides the same behavior as setting rel=»noopener» which does not set window.opener .
  • _parent : Load into the parent browsing context of the current one. If no parent, behaves the same as _self .
  • _top : Load into the top-level browsing context (i.e., the browsing context that is an ancestor of the current one and has no parent). If no parent, behaves the same as _self .

This value can be overridden by a formtarget attribute on a , , or element.

Examples

form method="get"> label> Name: input name="submitted-name" autocomplete="name" /> label> button>Savebutton> form> form method="post"> label> Name: input name="submitted-name" autocomplete="name" /> label> button>Savebutton> form> form method="post"> fieldset> legend>Do you agree to the terms?legend> label>input type="radio" name="radio" value="yes" /> Yeslabel> label>input type="radio" name="radio" value="no" /> Nolabel> fieldset> form> 

Result

Technical summary

Content categories Flow content, palpable content
Permitted content Flow content, but not containing elements
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts flow content
Implicit ARIA role form if the form has an accessible name, otherwise no corresponding role
Permitted ARIA roles search , none or presentation
DOM interface HTMLFormElement

Specifications

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Jun 13, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

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

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

Источник

Атрибут action

Указывает обработчик, к которому обращаются данные формы при их отправке на сервер. В качестве обработчика может выступать CGI-программа или HTML-документ, который включает в себя серверные сценарии (например, Parser). После выполнения обработчиком действий по работе с данными формы он возвращает новый HTML-документ.

Если атрибут action отсутствует, текущая страница перезагружается, возвращая все элементы формы к их значениям по умолчанию.

Синтаксис

Значения

В качестве значения принимается полный или относительный путь к серверному файлу (URL).

Обязательный атрибут

В HTML4 и XHTML обязателен, в HTML5 не обязателен.

Значение по умолчанию

В качестве обработчика можно указать адрес электронной почты, начиная его с ключевого слова mailto: . При отправке формы будет запущена почтовая программа установленная по умолчанию. В целях безопасности в браузере установлено, что отправить незаметно информацию, введенную в форме, по почте невозможно. Для корректной интерпретации данных используйте атрибут enctype=»text/plain» в теге .

Не выкладывайте свой код напрямую в комментариях, он отображается некорректно. Воспользуйтесь сервисом cssdeck.com или jsfiddle.net, сохраните код и в комментариях дайте на него ссылку. Так и результат сразу увидят.

Типы тегов

HTML5

Блочные элементы

Строчные элементы

Универсальные элементы

Нестандартные теги

Осуждаемые теги

Видео

Документ

Звук

Изображения

Объекты

Скрипты

Списки

Ссылки

Таблицы

Текст

Форматирование

Формы

Фреймы

Источник

HTML action Attribute

The HTML action attribute specifies where the form-data should be sent when the form is submitted. Its attribute value (URL) determines where the data must be sent after the form submission. The URL can have the following values:

  • absolute URL, which refers to another website link.
  • relative URL, which refers to a file within a webpage.

You can use this attribute only on the element.

Syntax

Example of the HTML action attribute:

html> html> head> title>Title of the document title> head> body> form action="/form/submit"> label for="fname">Name label> input type="text" name="FirstName" id="fname" value="Mary"/>br/>br/> label for="lname">Surname label> input type="text" name="LastName"id="lname" value="Thomson"/>br/>br/> input type="submit" value="Submit"/> form> body> html>

Источник

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