110 likes | 221 Views
Web Database Programming. Input Validation. User Input on the Web. Web browser built-in mechanisms HTML Forms HTTP POST method Hyperlinks HTTP GET method E.g. http://books.slashdot.org/article.pl?sid=02/06/11/2027240&tid=169&tid=6 Browser plug-ins User needs to install plug-in software
E N D
Web Database Programming Input Validation
User Input on the Web • Web browser built-in mechanisms • HTML Forms • HTTP POST method • Hyperlinks • HTTP GET method • E.g. http://books.slashdot.org/article.pl?sid=02/06/11/2027240&tid=169&tid=6 • Browser plug-ins • User needs to install plug-in software • Difficult for universal deployment • E.g. flash, Java applet
HTML Form • Container for UI controls • E.g. button, checkbox, etc. • Action: the URL of a program on the Web server that will receive the form data • E.g. PHP, CGI program, JSP, ASP, etc. • Method: the manner form data are sent over • “POST” or “GET” <FORM action="http://domain.name/program" method=“POST"> <!– form controls go here--> </FORM>
INPUT controls • type attribute • test, password, checkbox, radio, submit, reset, button, hidden • name attribute • value attribute • onclick • Can specify some Javascript code here • E.g. for client-side validation Name: <INPUT type="text" name=“username"><BR>Email: <INPUT type="text" name="email"><BR> <INPUT type="radio" name="sex" value="Male"> Male<BR> <INPUT type="radio" name="sex" value="Female"> Female<BR> <INPUT type="submit" value="Send"> <INPUT type="reset">
SELECT control • Create a menu • Must contain OPTION controls • Can select multiple items <SELECT multiple size=“2" name=“choices"> <OPTION selected value=“apple">Apple</OPTION> <OPTION selected value=“orange">Orange</OPTION> <OPTION>Banana</OPTION> <OPTION>Cherry</OPTION> <OPTION>Pear</OPTION> <OPTION>Grape</OPTION></SELECT>
More Controls • More INPUT types • TEXTAREA • BUTTON • Check HTML documentation
PHP form data processing • Data user entered are sent to PHP program specified by Action attribute • Method: POST, or GET (data append to URL) • In that PHP program, a data array is then automatically created • $_POST, or $_GET • Data of individual control can be accessed with the name of the control as key • E.g. $_POST[“username”]
Input Validation • Validate HTML form input from users • Error: user input do not match the expected input • E.g. expect zip code, user input street name Finding Errors Report Error User correct errors
Types of Input Validation • Server-side validation • Validation is done by the server • E.g. with PHP • More thorough, can check with data • E.g. credit card • Client-side validation • Validation is done by the browser • E.g. with Javascript • More interactive, reduce network load
Validation Strategy • Validate field by field • Immediate stop and report error is one is found • Batch Validation • Continue to validate until all errors found • Report all errors at once
Batch Validation with PHP • See http://www.albany.edu/~hy973732/courses/RISP566/Input.html