0
Forms & Validation · Introduction to Forms
New technique
What happens on submit
The visitor fills in a form, and the browser carries their answers to your server. Let's see how.
A <form> wraps a set of controls: text fields, checkboxes, buttons. It is the envelope the data travels in.
When the form is submitted, the browser collects every control that has a name, pairs each name with its value, and sends those pairs to the action URL using the method.
With method="get", the pairs go into the URL as a query string: a ? followed by name=value pairs, joined with &.
<form action="/search" method="get"> <label for="q">Search</label> <input id="q" name="q"> <button type="submit">Search</button> </form> <!-- typing “hammer” sends you to: /search?q=hammer -->
action→ where the data goes. Leave it out and the form posts to the current page.method→ how it travels:getorpost.- A GET form rebuilds the query string from its fields: anything already after the
?inactionis thrown away. Extra values belong in the form itself, for example as<input type="hidden" name="lang" value="en">.