Suggest an editImprove this articleRefine the answer for “What does the action attribute do on <form>?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)The **`action`** attribute on the `<form>` tag specifies the address (URL) to which the form data will be sent after the Submit button is clicked, usually the address of a server-side script that accepts and processes the data entered by the user. **Key point:** If `action` is not set or is empty, the form will submit the data to the page's current address.Shown above the full answer for quick recall.Answer (EN)ImageThe `action` attribute on the `<form>` tag specifies the **address (URL)** to which the **form data will be sent** after the **Submit** button is clicked (`<button type="submit">`). This is the address of a **handler** (usually a server-side script, PHP, Python, Node.js, and so on) that accepts and processes the data entered by the user. --- ### 1. Example ```html <form action="/send" method="post"> <input type="text" name="username" placeholder="Name"> <button type="submit">Submit</button> </form> ``` What happens: 1. The user enters their name. 2. When "Submit" is clicked, the browser builds a data set, for example: ```javascript username=Oleh ``` 3. It sends them to the server at `/send` (from `action`). --- ### 2. Possible values of `action` | Value | What it does | |---|---| | `/send` | Sends data to the specified path within the current site | | `https://example.com/api` | Sends data to an external server | | `""` (empty) | Sends data to the **current page** | | Attribute is missing | The same thing: the form submits **to itself** | Example: ```html <form action=""> <!-- the form will submit data to the current URL --> </form> ``` --- ### 3. How it works together with `method` - `method="get"` → the data is appended to the URL (in the browser's address bar): ```javascript /send?username=Oleh ``` - `method="post"` → the data is sent "in the body" of the HTTP request, not visible in the address bar. ```html <form action="/send" method="post"> ``` --- ### 4. If you specify a relative path ```html <form action="php/formHandler.php" method="post"> ``` → the data will go to `/current_folder/php/formHandler.php`. If an absolute address is needed: ```html <form action="https://mysite.com/api/contact" method="post"> ``` --- ### 5. Usage with JavaScript If processing happens not on the server but through JavaScript (for example, AJAX), `action` can be **ignored**: the script decides on its own where to send the data. Example: ```html <form id="form"> <input name="email"> <button>OK</button> </form> <script> document.getElementById('form').addEventListener('submit', e => { e.preventDefault(); // cancel the default submission console.log('Form submitted manually via JS'); }); </script> ``` --- ### Summary: | Attribute | Purpose | |---|---| | `action` | Specifies the address (URL) the browser will send the form data to | | Value | Relative or absolute URL | | If not set | Submits to the page's current address | | Works together with | `method="get"` or `method="post"` | | Used for | Linking the form to a server-side data handler | --- **In simple terms:** `action` is **"where to send the letter."** The form gathers data, and `action` tells the browser: > "Here is the recipient's address, take everything the user entered there."For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.