Except where otherwise noted, the contents of this presentation are Copyright 2009 Marty Stepp and Jessica Miller.
URL?name=value&name=value...
http://example.com/student_login.php?username=stepp&sid=1234567
username
has value stepp
, and sid
has value 1234567
<form>
(6.1.2)
<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>
(6.2.1)
<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>
(6.2.2)
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>
(6.2.3)
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" /> Pickles
on
:
http://webster.cs.washington.edu/params.php?tomato=on&pickles=on
checked="checked"
attribute in HTML to initially check the box<input>
(6.2.4)
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>
(6.2.5)
<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>
(6.2.6)
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
[]
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>
Array | Description |
---|---|
$_GET ,
$_POST
|
parameters passed to GET and POST requests |
$_REQUEST
|
parameters passed to any type of request |
$_SERVER ,
$_ENV
|
information about the web server |
$_FILES
|
files uploaded with the web request |
$_SESSION ,
$_COOKIE
|
"cookies" used to identify the user (seen later) |
<?php $base = $_REQUEST["base"]; $exp = $_REQUEST["exponent"]; $result = pow($base, $exp); ?> <?= $base ?> ^ <?= $exp ?> = <?= $result ?>
http://example.com/exponent.php?base=3&exponent=4
<?php foreach ($_REQUEST as $param => $value) { ?> <p>Parameter <?= $param ?> has value <?= $value ?></p> <?php } ?>
http://example.com/print_params.php?name=Marty+Stepp&sid=1234567
Parameter name has value Marty Stepp
Parameter sid has value 1234567
print_r
or var_dump
on $_REQUEST
for debugging