Except where otherwise noted, the contents of this document are Copyright 2012 Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
I changed the form's HTML code ... but when I refresh, the page doesn't update!
<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, sizeselected 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>
optgroups?<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 Picardvalue 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" ", "/", "=", "&""Marty's cool!?" → "Marty%27s+cool%3F%21"$_GET and $_POST arrays automatically decode themGET 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 is more appropriate than GET
GET requests embed their parameters in their URLs<form action="http://foo.com/app.php" 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>
if ($_SERVER["REQUEST_METHOD"] == "GET") {
# process a GET request
...
} elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
# process a POST request
...
}
$_SERVER array's "REQUEST_METHOD" elementinclude
include("filename");
include("header.html");
include("shared-code.php");
include_once,
require,
require_once