Selected content adapted from material by Marty Stepp, Jessica Miller, and Victoria Kirst © 2012. Used by permission.
URL?name=value&name=value...
http://www.google.com/search?q=Obama http://example.com/student_login?username=aardvark&id=1234567
username
has value aardvark
, and sid
has value 1234567
<form>
<form action="destination URL"> form controls </form>
action
attribute gives the URL of the page that will process this form's dataaction
's URL
<form action="http://www.google.com/search"> <div> Let's search Google: <input name="q" /> <input type="submit" /> </div> </form>
div
<input>
<!-- 'q' happens to be the name of Google's required parameter -->
<input type="text" name="q" value="Colbert Report" />
<input type="submit" value="Booyah!" />
input
element is used to create many UI controls
name
attribute specifies name of query parameter to pass to servertype
can be button
, checkbox
, file
, hidden
, password
, radio
, reset
, submit
, text
, ...value
attribute specifies control's initial text<input>
<input type="text" size="10" maxlength="8" /> NetID <br /> <input type="password" size="16" /> Password <input type="submit" value="Log In" />
input
attributes: disabled
, maxlength
, readonly
, size
, value
size
attribute controls onscreen width of text fieldmaxlength
limits how many characters user is able to type into field<textarea>
a multi-line text input area (inline)
<textarea rows="4" cols="20"> Type your comments here. </textarea>
textarea
tag (optional)rows
and cols
attributes specify height/width in charactersreadonly
attribute means text cannot be modified<input>
yes/no choices that can be checked and unchecked (inline)
<input type="checkbox" name="lettuce" /> Lettuce <input type="checkbox" name="tomato" checked="checked" /> Tomato <input type="checkbox" name="pickles" checked="checked" /> Pickles
on
:
http://webster.cs.washington.edu/params.php?tomato=on&pickles=on
checked="checked"
attribute in HTML to initially check the box<input>
sets of mutually exclusive choices (inline)
<input type="radio" name="cc" value="visa" checked="checked" /> Visa <input type="radio" name="cc" value="mastercard" /> MasterCard <input type="radio" name="cc" value="amex" /> American Express
name
attribute (only one can be checked at a time)value
for each one or else it will be sent as value on
<label>
<label><input type="radio" name="cc" value="visa" checked="checked" /> Visa</label> <label><input type="radio" name="cc" value="mastercard" /> MasterCard</label> <label><input type="radio" name="cc" value="amex" /> American Express</label>
label
element can be targeted by CSS style rules<select>
,
<option>
menus of choices that collapse and expand (inline)
<select name="favoritecharacter"> <option>Jerry</option> <option>George</option> <option selected="selected">Kramer</option> <option>Elaine</option> </select>
option
element represents each choiceselect
optional attributes: disabled
, multiple
, size
selected
attribute sets which one is initially chosen<select>
for lists<select name="favoritecharacter[]" size="3" multiple="multiple"> <option>Jerry</option> <option>George</option> <option>Kramer</option> <option>Elaine</option> <option selected="selected">Newman</option> </select>
multiple
attribute allows selecting multiple items with shift- or ctrl-click
[]
(for PHP) if you allow multiple selections
option
tags can be set to be initially selected
<optgroup>
<select name="favoritecharacter"> <optgroup label="Major Characters"> <option>Jerry</option> <option>George</option> <option>Kramer</option> <option>Elaine</option> </optgroup> <optgroup label="Minor Characters"> <option>Newman</option> <option>Susan</option> </optgroup> </select>
Name: <input type="text" name="name" /> <br /> Food: <input type="text" name="meal" value="pizza" /> <br /> <label>Meat? <input type="checkbox" name="meat" /></label> <br /> <input type="reset" />
value
attributeI changed the form's HTML code ... but when I refresh, the page doesn't update!
<input type="text" name="username" /> Name <br /> <input type="text" name="sid" /> SID <br /> <input type="hidden" name="school" value="Gordon" /> <input type="hidden" name="year" value="2048" />
<input type="text" name="name" /> Name <br /> <input type="text" name="sid" /> SID <br /> <input type="submit" name="action" value="Go For It!" /> <input type="button" name="another-action" value="Do Something Else..." />
<fieldset>
,
<legend>
groups of input fields with optional caption (block)
<fieldset> <legend>Credit cards:</legend> <input type="radio" name="cc" value="visa" checked="checked" /> Visa <input type="radio" name="cc" value="mastercard" /> MasterCard <input type="radio" name="cc" value="amex" /> American Express </fieldset>
fieldset
groups related input fields, adds a border; legend
supplies a captionelement[attribute="value"] { property : value; property : value; ... property : value; }
input[type="text"] { background-color: yellow; font-weight: bold; }
input
)<label><input type="radio" name="cc" /> Visa</label> <label><input type="radio" name="cc" /> MasterCard</label> <br /> Favorite Star Trek captain: <select name="startrek"> <option>James T. Kirk</option> <option>Jean-Luc Picard</option> </select> <br />
[cc] => on, [startrek] => Jean-Luc Picard
value
attribute<label><input type="radio" name="cc" value="visa" /> Visa</label> <label><input type="radio" name="cc" value="mastercard" /> MasterCard</label> <br /> Favorite Star Trek captain: <select name="startrek"> <option value="kirk">James T. Kirk</option> <option value="picard">Jean-Luc Picard</option> </select> <br />
value
attribute sets what will be submitted if a control is selected[cc] => visa, [startrek] => picard
" "
, "/"
, "="
, "&"
"Anthony's cool!?"
→ "Anthony%27s+cool%3F%21"
Request.QueryString
user_name = Request.QueryString["username"]; id_number = (int) Request.QueryString["id"]; eats_meat = FALSE; if (Request.QueryString.AllKeys.Any(k => k == "meat")) { $eats_meat = TRUE; }
$_REQUEST["parameter name"]
returns a parameter's value as a string Request.QueryString.AllKeys.Any
GET
vs. POST
requests
GET
: asks a server for a page or data
POST
: submits data to a web server and retrieves the server's response
POST
request is more appropriate than a GET
GET
requests embed their parameters in their URLs@{ var firstName = Request.QueryString["fname"]; var lastName = Request.QueryString["lname"]; var result = "Hello " + firstName + " " + lastName; @result; }
http://example.com/hello?fname=Donald&lname=Trump
@{ foreach (var key in Request.QueryString.AllKeys) { <p>Parameter @key has value @Request.QueryString[key]</p> } }
http://example.com/printparams?name=Orycteropus+afer&sid=1234567
Parameter name has value Orycteropus afer
Parameter sid has value 1234567
<form action="http://foo.com/app" method="post"> <div> Name: <input type="text" name="name" /> <br /> Food: <input type="text" name="meal" /> <br /> <label>Meat? <input type="checkbox" name="meat" /></label> <br /> <input type="submit" /> <div> </form>