Web Programming Step by Step: Reset Buttons (6.2.7)
Web Programming Step by Step: Reset Buttons (6.2.7)
when clicked, returns all form controls to their initial values specify custom text on the button by setting its value attribute
fieldset groups related input fields, adds a border; legend supplies a caption
attribute selector: matches only elements that have a particular attribute value useful for controls because many share the same element (input)
an invisible parameter that is still passed to the server when form is submitted useful for passing on additional state that isn't modified by the user
this form submits to our handy params.php tester page the form may look correct, but when you submit it... [cc] => on, [startrek] => Jean-Luc Picard
value attribute sets what will be submitted if a control is selected [cc] => visa, [startrek] => picard
URL-encoding (6.3.1)
certain characters are not allowed in URL query parameters: examples: " ", "/", "=", "&" when passing a parameter, it is URL-encoded (reference table) "Marty's cool!?" "Marty%27s+cool%3F%21" you don't usually need to worry about this: the browser automatically encodes parameters before sending them the PHP $_REQUEST array automatically decodes them ... but occasionally the encoded version does pop up (e.g. in Firebug)
GET or POST?
if ($_SERVER["REQUEST_METHOD"] == "GET") { # process a GET request ... } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { # process a POST request ... }
some PHP pages process both GET and POST requests to find out which kind of request we are currently processing, look at the global $_SERVER array's "REQUEST_METHOD" element
add a file upload to your form as an input tag with type of file must also set the enctype attribute of the form it makes sense that the form's request method must be post (an entire file can't be put into a URL!) form's enctype (data encoding type) must be set to multipart/form-data or else the file will not arrive at the server
PHP superglobal arrays contain information about the current request, server, etc.: These are special kinds of arrays called associative arrays.
associative array (a.k.a. map, dictionary, hash table) : uses non-integer indexes associates a particular index "key" with a value key "marty" maps to value "206-685-2181" syntax for embedding an associative array element in interpreted string:
print "Marty's number is {$blackbook['marty']}.\n";
Uploading details
<input type="file" name="avatar" />
example: if you upload borat.jpg as a parameter named avatar, $_FILES["avatar"]["name"] will be "borat.jpg" $_FILES["avatar"]["type"] will be "image/jpeg" $_FILES["avatar"]["tmp_name"] will be something like "/var/tmp /phpZtR4TI"
functions for dealing with uploaded files: is_uploaded_file(filename) returns TRUE if the given filename was uploaded by the user move_uploaded_file(from, to) moves from a temporary file location to a more permanent file proper idiom: check is_uploaded_file, then do move_uploaded_file
inserts the entire contents of the given file into the PHP script's output page encourages modularity useful for defining reused functions needed by multiple pages