[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
This lecture introduces HTML Forms, a way how an HTML page can provide input fields, so that users can provide data to a Web-based application. HTML forms are regular HTML pages (i.e., using regular HTML structures), but they also contain special HTML elements for data entry. Most importantly, each form contains instructions on how to submit the entered data, and the browser will use that information to send an HTTP request containing all the data of the form submission.
<form action="http://stevex.net/dump.php" method="POST" enctype="multipart/form-data"><table> <tr><td>Text:</td><td><input type="text" name="text" value="text input"/></td></tr> <tr><td>Password:</td><td><input type="password" name="password" value="hidden text"/></td></tr> <tr><td>Checkbox:</td><td><input type="checkbox" name="check" value="1"/> <input type="checkbox" name="check" value="2"/> <input type="checkbox" name="check" value="3"/></td></tr> <tr><td>Radio Button:</td><td><input type="radio" name="radio" value="1"/> <input type="radio" name="radio" value="2"/> <input type="radio" name="radio" value="3"/></td></tr> <tr><td>Text Areas:</td><td><textarea name="textarea" rows="2" cols="20"/></td></tr> <tr><td>Selection:</td><td><select name="select"><option selected="selected">XML</option><option>SGML</option></select></td></tr> <tr><td>Multiple Selection:</td><td><select name="mselect" multiple="multiple"><option>242</option><option>290-3</option><option>290-13</option></select> <tr><td>File Upload:</td><td><input name="file" type="file"/></td></tr> <tr><td valign="top" align="right">Hidden:</td><td><input type="hidden" name="hidden" value="hidden input"/></td></tr> <tr><td>Submit:</td><td><input name="submit" type="submit"/></td></tr> </table></form>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript Datepicker</title> <script type="text/javascript" src="date-picker.js"></script> <link rel="stylesheet" type="text/css" href="date-picker.css"> </head> <body> <form action="http://stevex.net/dump.php" method="GET"> <input type="text" name="date"> <input type="button" value="calendar" onclick="displayDatePicker('date');"> <input type="submit" value="submit date"> </form> </body> </html>
POST
)GET
is good!GET
when implementing a formGET
encodes the values in the URIPOST
request method can upload dataPOST
sends a request containing an entityPOST
is used if the form specifies itapplication/x-www-form-urlencoded
is the default (values in the entity)multipart/form-data
is required for file upload (multipart form data)POST
requestsGET
/POST
transparentlyGET
POST
POST
with multipart/form-data
<p>Query Parameter Test:</p> <p>test: <?php echo $_REQUEST["test"]; ?></p> <p>name: <?php echo $_REQUEST["name"]; ?></p> <p>field: <?php echo $_REQUEST["field"]; ?></p>
<tr><td>Text:</td><td><input type="text" name="text"/></td></tr> <tr><td>Password:</td><td><input type="password" name="password"/></td></tr>
<tr> <td><label for="textctrl">Text:</label></td> <td><input type="text" name="text" id="textctrl"/></td> </tr> <tr> <td><label for="pwdctrl">Password:</label></td> <td><input type="password" name="password" id="pwdctrl"/></td> </tr>
<fieldset><legend>Billing</legend>billing form HTML …</fieldset> <fieldset><legend>Shipping</legend> shipping form HTML … </fieldset>
Normal Control | Disabled Control | Readonly Control | |
---|---|---|---|
Text: | |||
Password: | |||
Checkbox: | ! | ||
Radio Button: | ! | ||
File Upload: | ! | ||
Text Areas: | |||
Selection: | [ not supported ] | ||
Multiple Selection: |
<table style="margin : 2% ; width : 90% ; " rules="groups" cellpadding="5"> <thead><tr> <td></td> <th>Normal Control</th> <th>Disabled Control</th> <th>Readonly Control</th> </tr></thead> <tbody> <tr><td valign="top" align="right">Text:</td><td><input type="text" name="text1" value="text input"></td><td><input disabled="disabled" type="text" name="text2" value="text input"></td><td><input readonly="readonly" type="text" name="text3" value="text input"></td></tr> <tr><td valign="top" align="right">Password:</td><td><input type="password" name="password1" value="hidden text"></td><td><input disabled="disabled" type="password" name="password2" value="hidden text"></td><td><input readonly="readonly" type="password" name="password3" value="hidden text"></td></tr> <tr><td valign="top" align="right">Checkbox:</td><td><input type="checkbox" name="check1" value="1"> <input type="checkbox" name="check1" checked="checked" value="2"> <input type="checkbox" name="check1" value="3"></td><td><input disabled="disabled" type="checkbox" name="check2" value="1"> <input disabled="disabled" type="checkbox" name="check2" checked="checked" value="2"> <input disabled="disabled" type="checkbox" name="check2" value="3"></td><td><input readonly="readonly" type="checkbox" name="check3" value="1"> <input readonly="readonly" type="checkbox" name="check3" checked="checked" value="2"> <input readonly="readonly" type="checkbox" name="check3" value="3"> !</td></tr>