|
home—lects—exams—hws
D2L—breeze (snow day)
From PHP Visual Quickstart Guide by Larry Ullman
Originally based on notes by Jack Davis (jcdavis@radford.edu)
<input type='checkbox' name='cb1' value='milk' id='cbOne' checked='checked' /> |
<input type='text' name='txt1' size='10' maxlength='8' id='txtone' /> |
<input type='radio' name='age' value='over50' /> <br/> <input type='radio' name='age' value='30to50' /> <br/> <input type='radio' name='age' value='under30' /> <br/> |
<textarea name='comments' rows='3' cols='30'> Initial Contents </textarea> |
(I'm not really sure why text areas are different from
from checkboxes/radio-buttons/text-fields1.
It'd seem more sensible to either have a single tag
<select name='title'> <option value = 'mr'>Mr.</option> <option value = 'ms'>Ms.</option> <option value = 'mrs'>Mrs.</option> <option value = 'miss'>Miss</option> </select> |
<input type='submit' value='Submit Data to Server' /> |
<input type='reset' value='Clear Form' /> |
Q: But how is information communicated from a web form (pure html) to a php program?
A: When you click 'submit', the HTML makes a page-request to the page specified by the form's "action" attribute.
(Presumably it's a php page.)
The page-request incudes extra information about what html input fields had been selected, etc..
The server gets that request and invokes the php file as normal, but it also
pre-initializes an array of values for the program — and it fills that array with
the extra information contained in the page-request.
You must both (i) tell php whether to display errors, and (ii) what level of errors to display (notices, warnings, errors, etc.).
Note that telling php to display errors
by calling a function at the start of your program (
<?php error_reporting(E_ALL | E_STRICT); // Tell php to report errors ini_set('display_errors', True); // Tell apache to include stderr w/ the html-output ini_set('display_startup_errors', True); // Pointless, for this file -- startup is already finished. ?> |
<?php error_reporting(E_ALL | E_STRICT); // Tell php to report errors ini_set('display_errors', True); // Tell apache to include stderr w/ the html-output ini_set('display_startup_errors', True); // Useful for any *later* include'd files include('someFile-for-real.php'); ?> |
# .htaccess -- a configuaration file which affects all files Apache serves # in its directory, as well as everything below that directory. # You might have this file in your personal root-php directory, # and other (cascading) such files in selected sub-directories. # Note: .htaccess on rucs.radford.edu does NOT allow setting php_value # (it will result in all pages generating a 500 error) # Turn on error-reporting: php_value display_errors True php_value display_startup_errors True # Note: for production you might want to configure to *log* errors instead of *display* # Note: you can also set this to "stderr" instead of "True" php_value error_reporting 32767 # Note: this should be whatever <?php echo E_ALL|E_STRICT;?> shows. |
<?php error_reporting(E_ALL | E_STRICT); ini_set('display_errors', True); ini_set('display_startup_errors', True); // in case we include other files ?> |
As we saw,
we can combine values (to use as an argument to
See also various error functions.
1
Note that everything the HTML designers bundled together
under the
2 Perhaps because “PHP is run in CGI mode, not as an Apache module”, as suggested by php-value. ↩
home—lects—exams—hws
D2L—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2012.May.31 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |