HTML Form Action and Method

Form Action and Method: Where the Data Goes and How

A form isn't complete until you tell it two things: where to send the data, and how to send it. That's exactly what the action and method attributes define in an HTML form.

What is the action Attribute?

The action attribute tells the form where to send the submitted data — usually a URL or server-side script that processes it.

Example: Submitting to a Script

<form action="/submit-fruit" method="post">
  <input type="text" name="fruit" placeholder="Apple">
  <input type="submit" value="Send">
</form>
[ Apple           ] [Send]

When you click "Send", the browser sends the form data to /submit-fruit.

What if action is Missing?

If you omit the action, the form submits to the same page it’s on.

<form method="post">
  ...
</form>

This can be useful for self-processing forms (e.g., feedback forms that reload the page).

What is the method Attribute?

The method tells the browser how to send the data. There are two common values:

  • get: Appends the form data to the URL (visible)
  • post: Sends data in the request body (hidden)

GET Method Example

<form action="/search" method="get">
  <input type="text" name="q" placeholder="Banana">
  <input type="submit" value="Search">
</form>
[ Banana          ] [Search]

If you search for "banana", the browser will navigate to:

/search?q=banana

GET is ideal for search forms or any action that doesn’t change data.

POST Method Example

<form action="/register" method="post">
  <input type="text" name="name" placeholder="Hello World"><br>
  <input type="submit" value="Register">
</form>

With post, the data goes in the request body — invisible in the browser’s address bar. Use this when collecting sensitive or permanent data like registrations or updates.

Choosing Between get and post

| Use Case | Method | Why | |--------------------|--------|------------------------------------| | Search queries | get | Easy to share/bookmark results | | Login or signup | post | Data is private and stored | | Poll voting | post | Prevent manipulation via URL | | Filtering items | get | Safe for navigation and SEO |

Full Example: Fruit Feedback Form

<form action="/submit-feedback" method="post">
  <label for="fruit">Fruit:</label><br>
  <input type="text" id="fruit" name="fruit" placeholder="Cherry" required><br><br>

  <label for="comment">Your Comment:</label><br>
  <textarea id="comment" name="comment" rows="4" cols="40" required></textarea><br><br>

  <input type="submit" value="Submit">
</form>
Fruit: [ Cherry           ]  
Your Comment:
[                                      ]
[                                      ]
[                                      ]
[                                      ]

[Submit]

Best Practices

  • Use get for search and filters — when data isn’t sensitive
  • Use post for anything stored, updated, or private
  • Always define an action so your form knows where to go

Summary

HTML forms communicate with servers through action and method. You now know how to:

  • Define the destination URL using action
  • Choose between get and post based on your use case
  • Test and observe how forms behave differently with each method

Check your understanding 1

What does the action attribute in a <form> element specify?
Choose one answer. You can try again.

Answer and explanation

It specifies the URL where form data is sent

The action attribute tells the browser where to send the form data once the user submits the form. For example: action="/submit-marks.php".

Check your understanding 2

The method attribute defines the HTTP method (GET or POST) used when submitting a form.
Choose one answer. You can try again.

Answer and explanation

True

Correct. method="get" appends data to the URL, while method="post" sends data in the body, making it suitable for sensitive or long input.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. GET
  2. POST
  3. PUT
  4. DELETE
Which of the following are valid values for the method attribute in HTML forms?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2

HTML forms only support GET and POST methods. PUT and DELETE are part of REST APIs and require JavaScript or external tools.

Check your understanding 4

Which method should you use for a feedback form that collects long responses and sensitive data?
Choose one answer. You can try again.

Answer and explanation

<code>method="post"</code>

Use post for forms containing personal or lengthy data (like a student feedback form) because it transmits data securely in the request body.

Check your understanding 5

If the action attribute is left blank, the form submits to the same page it’s on.
Choose one answer. You can try again.

Answer and explanation

True

Yes, an empty action means the form data will be submitted to the current page’s URL, which is useful for self-processing forms like admission updates.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. <form action="/submit-student.php" method="post">
  2. <form method="get" action="results.php">
  3. <form method="delete" action="/delete.php">
  4. <form action="" method="post">
Which of the following are correct form configurations?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2 and 4

Forms 0, 1, and 3 are valid. The third is valid because action being blank defaults to the same page. The third option with method="delete" is not valid HTML — DELETE isn’t supported in standard HTML forms.

What’s Next?

Ready to group and organize your form content? Let’s explore <fieldset> and <legend> — structure that makes your forms more readable and accessible.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: HTML Fieldset and Legend →