CyberStars

Where a Form Goes

A letter without an address on the envelope goes nowhere, however nice the letter is. A form is the same. It needs to know where to go, and how to get there.

action: where it goes

A server reads a form: a computer somewhere that does something with it. It saves an order, or it looks for games. The action attribute holds the address of the server's page that reads the form:

<form action="https://games.example/search">
  <label for="q">Search games</label><br />
  <input id="q" name="q" />
  <button>Search</button>
</form>

Type chess and click Search. Here, like in your editor, the page stays where it is, and the line under it says what the form would send. On a real website, the browser would open this address:

https://games.example/search?q=chess

That's the form's address, a ?, then the same name=value pairs, joined by &. A form without an action goes to the address of its own page.

method: how it goes

The method attribute says how the pairs travel. There are two ways.

get puts them in the address, like above. A form does this when it has no method. It's good for a search: you can save the address, send it to a friend, and open the same results again.

post puts them inside the message to the server, not in the address. The address bar only shows the action. Use it when the form changes something, like an order, a sign-up or a booking, and when it holds personal details:

<form action="https://pizza.example/order" method="post">

On a real website, the browser opens https://pizza.example/order, and nothing after it. In the editor and here, the page still stays where it is. You only see the difference on a real server.

Break it on purpose

Forget the method on the pizza order. Ida orders a pizza, and the browser opens:

https://pizza.example/order?name=Ida+Moreau&address=12+Lake+Street

A + is a space in an address. Now Ida's home address is in the address bar, for anyone behind her to read. It's in the browser's history, and in the link she copies to a friend. Personal details don't belong in an address bar.


Mission: Where does it go?

What you will see: the page looks the same, and the console still shows the line of what is sent. The difference is in where the form would go.

Your booking form has no action, so it would go back to boarding.html, where nobody reads it. The station's server reads bookings at https://station.example/book.

  • The form goes to https://station.example/book.
  • A booking holds personal details, so they never show in the address bar.
  • The form still sends every box as before.