<form>
defines how data will be sent
action
where data is sent (with no action, its sent to the same page)
<!--absolute url -->
<form action="https://example.com">
<!--relative url -->
<form action="/somewhere_else">
method
how data is sent (GET versus POST)
GET
retrieve data from
Data sent in key:value pairs
<form action="http://www.foo.com" method="GET">
<div>
<label for="say">What greeting do you want to say?</label>
<input name="say" id="say" value="Hi">
</div>
<div>
<label for="to">Who do you want to say it to?</label>
<input name="to" id="to" value="Mom">
</div>
<div>
<button>Send my greetings</button>
</div>
</form>
HTTP Request:
GET /?say=Hi&to=Mom HTTP/2.0
Host: foo.com
POST
send data to the server
<form action="http://www.foo.com" method="POST">
<div>
<label for="say">What greeting do you want to say?</label>
<input name="say" id="say" value="Hi">
</div>
<div>
<label for="to">Who do you want to say it to?</label>
<input name="to" id="to" value="Mom">
</div>
<div>
<button>Send my greetings</button>
</div>
</form>
POST / HTTP/2.0
Host: foo.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 13
say=Hi&to=Mom
In Chrome:
Extra steps:
method="post"
enctype ="multipart/form-data"
<input type="file">
<form method="post" action="https://www.foo.com" enctype="multipart/form-data">
<div>
<label for="file">Choose a file</label>
<input type="file" id="file" name="myFile">
</div>
<div>
<button>Send the file</button>
</div>
</form>
All data that comes to your server must be checked and sanitized. Always. No exception.