(X)HTML Forms and PHP

Jussi Pohjolainen

Tampere University of Applied Sciences

Http

HTTP GET


telnet www.uta.fi 80
Trying 153.1.6.41...
Connected to www.uta.fi.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 12 Jan 2007 07:51:41 GMT
Server: Apache/1.3.37 (Unix)
Last-Modified: Wed, 10 Jan 2007 12:43:34 GMT
ETag: "479a0-16a9-45a4df76"
Accept-Ranges: bytes
Content-Length: 5801
Connection: close
Content-Type: text/html; charset=iso-8859-1

(X)HTML Forms and HTTP

Difference between GET and POST

Handling forms in PHP

Examples of using GET and POST

Example forms

Radio Buttons
Coffee Tea
<form action="foo.php" method="POST">
 <input type="radio" name="choice" value="coffee">Coffee
 <input type="radio" name="choice" value="tea">Tea<br/>
</form>
$ch = $_GET['choice'];
Check Boxes
Pizza Coca-Cola
<form action="foo.php" method="GET">
 <input type="checkbox" name="pizza"> Pizza
 <input type="checkbox" name="coke"> Coca-Cola<br/>
</form>
if(isset($_GET['pizza'])) 
{ 
   ... 
}
Drop-down menu:
<form action="foo.php" method="GET">
  <select name="drink">
	<option>Beer</option>
	<option>Wine</option>
  </select>
</form>
$ch = $_GET['drink'];

Sending information to the same page

Hidden information in forms