HTML Form Action URL Explained: Where a Form Really Sends
What the form action and method attributes do, what happens on submit, and how to point a form on any site builder at an external endpoint.
In this post
Every HTML form has an address where its data goes, and that address is set by the action attribute. Most form problems come from not knowing what that address is or how the data travels to it. This post explains the action and method attributes, the enctype attribute and file uploads, what happens when a visitor presses submit, and how to point a form at an external address, whether the site runs on WordPress, Shopify or plain HTML.
What the action attribute is
The action attribute is set on the form element. According to the MDN reference for the form element, it is the URL that processes the form submission. The browser sends the submission to that URL, so the action is the answer to the question "where does this form really send?"
The attribute can be overridden for a single button. A formaction attribute on a submit button sends that button's submission to a different URL. The MDN reference says this override applies to button and to input elements of type submit or image. So if a form seems to send to the wrong place, check the buttons inside it as well as the form element.
GET versus POST
The method attribute sets how the data travels. According to MDN, the allowed values are get, post and dialog, and get is the default.
With get, the browser appends the form data to the action URL after a ?. The data becomes part of the address, which is visible in the browser's address bar and in server logs. With post, the data is sent in the body of the request, not in the address. MDN says to use get when the form has no side effects. A form that does have side effects, such as storing a message, is the case for post.
That gives a concrete rule for contact forms. A form that creates a record, sends an email or stores a message should use post. A form that only searches or filters can use get. If your contact form uses get, the message text ends up in the address, which is rarely what you want.
What happens when the visitor presses submit
When the visitor presses the submit button, the browser builds the form's data and sends it to the action URL with the method you chose. The server at that URL receives the request and decides what to do with it: store it, check it, or send it on.
The page's own code does not handle the result. What the visitor sees afterwards depends on the response from that URL, so a missing or failing endpoint can leave the visitor with an error or a blank page, not a confirmation from your site. This is why a form can look fine and still lose messages: the failure happens at the receiving end.
enctype and file uploads
The enctype attribute sets the MIME type of the submission, and MDN says it applies only when the method is post. The default is application/x-www-form-urlencoded. The value multipart/form-data is needed when the form contains an input of type file. MDN says to use multipart/form-data if the form contains input elements with type=file. The third value, text/plain, is described by MDN as useful for debugging.
The practical rule: a contact form with an attachment field needs method="post" and enctype="multipart/form-data". Without the second attribute, the file is not sent as a file.
Pointing a form at an external address
To send a form to an external endpoint, set the action to that endpoint's full URL and choose a method the endpoint accepts. The action is simply a URL, so an external address works the same way as a local one, provided the receiving end accepts the request it gets. An external service or your own server must be ready for the method and the field names in the form.
On a site builder, the form may not be written by hand. WordPress, Shopify and other builders often provide a form block, a theme setting or an embed option. The attribute to find is still action, and you can check it in the page source after publishing: the rendered form tag shows the address the browser will use. If the builder hides the action, the form cannot be pointed elsewhere without a plugin, a theme edit or a different embed.
On a plain static site, the form tag is in the page file itself, so the action and method sit right in the markup.
What the receiving end must do
The receiving end has three jobs. It must accept the method the form uses, so a post form needs an endpoint that accepts post. It must read the field names the form sends, which means the names in the form and the names the endpoint expects must match. And it must answer, so the browser has a response to show.
Check all three before you go live. Submit a test message from the live page, not from a local copy, and confirm that it arrives with every field. A form that has been tested only on the page it was built on has not been tested.
Common mistakes
These are the mistakes that come up most often, and each one is visible in the markup:
- A wrong or outdated action URL. The endpoint moved or was retired, and the form still points at the old address.
- The wrong method. A
getform sends its data in the address, and apost-only endpoint rejects it. - Missing name attributes. The browser sends only the controls that have a
name, so a field without one never reaches the receiving end. - Missing enctype on a file field. The file is not sent as a file.
- A button with a formaction override. The form's
actionlooks right, but one button sends somewhere else.
Each one can be found by reading the rendered form tag and submitting a test message from the live page.
Many sites, one receiving address
If you run several sites, each form can point at the same receiving address, or each can point at its own. Sharing one address means one endpoint to maintain and one inbox to read, but each form must still send a field that tells the endpoint which site and page it came from. Without that field, a shared address gives you one stream of messages that you cannot sort.
Using a separate address per site keeps messages apart, at the cost of more forms to check when something changes. Either way, write down the address each form uses, so that a change on one site does not silently break another. How Prosphere works describes the planned approach to one receiving address for many sites, which is in build. For the inbox side, see the shared inbox, and for a waitlist, see the contact page.
Sources
- MDN, the
formelement,action,method,enctypeandformaction: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/form