Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

action — the form submission URL

`action` names the form’s destination, but the submitting button can override it with its own `formaction`.

Version: HTML Living Standard

Syntax

<form action="/save"><button formaction="/preview">Preview</button></form>

On form, provide a valid nonempty relative or absolute URL. Relative URLs resolve against the document’s base URL. If the attribute is missing, submission uses the document URL; an empty attribute may behave similarly but is not a conforming authored value.

action does not choose the HTTP method, encoding, or target browsing context: those belong to method, enctype, and target. A submit button’s formaction takes precedence for its submission. The URL is neither input validation nor CSRF protection; do not submit secrets with GET.

The example calls requestSubmit() with a particular button. The form names /save, but the GET request goes to /preview?q=two+words. A local fixture confirms that destination. Without the fixture, the example needs a matching server route.

Examples

<!doctype html><meta charset="utf-8">
<form id="form" action="/save" method="get" target="receipt">
<label>Query <input name="q" value="two words"></label>
<button id="preview" formaction="/preview">Preview</button></form>
<iframe id="receipt" name="receipt" title="Submission receipt" hidden></iframe>
<output id="result"></output>
<script>
const form = document.querySelector('form');
document.querySelector('#receipt').addEventListener('load', event => {
  const response = event.target.contentDocument.querySelector('#received');
  if (response) document.querySelector('#result').textContent = response.textContent;
});
form.requestSubmit(document.querySelector('#preview'));
</script>

Result

GET /preview?q=two+words

The test observes the real form request and confirms that `/save` receives none; no production server is contacted.

Sources