<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Challenge</title>
</head>
<body>
<p>
Halt! Who goes there?
</p>
<form action="response.py" method="get">
<input type="text" name="firstname" />
<input type="text" name="surname" />
<input type="submit" />
</form>
</body>
</html>
form elementform start tag has two attributes:
action: the URL of the program that will handle the datamethod: an HTTP command, e.g. GET or POSTform element contains 'controls' such as textfields, radio buttons,
menus, etc.
input element and its type and name attributesinput elementtype attribute specifies what kind of control we want:
text, password, …
name attribute is required for all types except reset and
submit.
input element with type="text":
<input type="text" />
<input type="text" name="surname" />
size attribute to change its width:
<input type="text" name="surname" size="25" />
maxlength attribute to restrict this:
<input type="text" name="surname" size="25" maxlength="25" />
value attribute to supply your own initial value:
<input type="text" name="num_children" size="25" maxlength="25" value="0" />
disabled:
<input type="text" name="total_cost" size="10" value="34.99" disabled />
input element with attribute type="reset":
<input type="reset" />
<input type="reset" value="CLEAR" />
input element with attribute type="submit":
<input type="submit" />
<input type="submit" value="GO!" />
title attributeplaceholder attributelabel elementtitle attributetitle attribute causes a tooltip to appear when the user hovers over the field<input type="text" name="zip"
title="A valid US zip code or UK postcode. For other countries, leave blank." />
placeholder attributeplaceholder attribute<input type="text" name="firstname" placeholder="Your first name" />
placeholder differ from value?label elementSurname: <input type="text" name="surname" />
label tag:
<label>Surname:</label> <input type="text" name="surname" />
placeholder be better than label?for attributelabel and the text field
id attribute on the text field (we'll use the same value as the name but they're different things)for attribute on the label
<label for="surname">Surname:</label> <input type="text" name="surname" id="surname" />
labelsform element, group together related controls using a fieldset elementlegend element nested in the fieldset to describe the group of controls<form>
<fieldset>
<legend>Name</legend>
<label for="firstname">First name: </label>
<input type="text" name="firstname" id="firstname" />
<label for="surname">Surname: </label>
<input type="text" name="surname" id="surname" />
</fieldset>
<fieldset>
<legend>Address</legend>
<label for="street_address">Street address: </label>
<input name="street_address" id="street_address" />
<label for="town">Town: </label>
<input name="town" id="town" />
</fieldset>
<fieldset>
<input type="reset" />
<input type="submit" />
</fieldset>
</form>
label {
display: block;
}
label {
float: left;
clear: left;
width: 10em;
margin-right: 1em;
text-align: right;
}
input {
float: right;
clear: right;
}
<form action="https://www.google.com/search" method="get">
<label for="search">Oogle: </label>
<input type="text" name="q" id="search" />
<input type="submit" />
</form>
<form action="https://www.imdb.com/find" method="get">
<label for="search">MovieMe: </label>
<input type="text" name="q" id="search" />
<input type="submit" />
</form>