Form basics
Form action
The form action is the HTML attribute that holds the URL a form is sent to when the visitor submits it. Without it, the form posts to the page it is on.
Also called: action attribute, form action URL, formaction
Every <form> element can carry an action attribute. It tells the browser where to send the data when the form is submitted.
<form method="POST" action="https://api.staticform.app/api/v1/forms/YOUR_FORM_ID">
<input type="email" name="email" required />
<button type="submit">Send</button>
</form>
What happens without it
If action is left out, the browser sends the form to the URL of the current page. On a page served by an application that is normal: the same route handles the form. On a static site it fails, because the host only serves files and nothing accepts the submission. That is the usual reason a static contact form seems to do nothing or returns an error such as “405 Method Not Allowed”.
Absolute or relative
A relative value such as /contact sends the form to your own domain. An absolute URL sends it to another host, which is how a form on your site reaches a form backend elsewhere. Use the full https:// address.
The method and enctype go with it
The action says where, the method says how, and enctype says how the fields are encoded. A form with a file upload needs enctype="multipart/form-data" (see multipart form data).
formaction on a button
A submit button can carry its own formaction, which overrides the form’s action for that button. It is useful when one form has two buttons that go to different places, and rarely needed otherwise.
In StaticForm
The form’s action is its StaticForm endpoint, shown in the dashboard with your form ID filled in. Post with application/x-www-form-urlencoded or multipart/form-data; JSON request bodies are not accepted at the submission endpoint. By default StaticForm answers with JSON, and you can switch the form to redirect the browser to a success or error page instead, which suits plain HTML forms without JavaScript.
Learn more
Related terms
- GET vs POSTGET and POST are the two HTTP methods an HTML form can use. GET adds the fields to the URL, while POST sends them in the body of the request.
- Form backendA form backend is a service that receives what a website form submits, then validates it, stores it, filters spam and sends it on to email, a spreadsheet or another tool.
- Multipart form datamultipart/form-data is a way to encode a form submission as separate parts, one per field. HTML forms need it whenever they include a file upload.