Form follows function
♫ Saturday, May 17th, 2003In order to get put data in the database, we need to ask the user for that information. To do that in html, we use a form. Below is a simple form that shows some of the basic controls that can be used in a form. If you click here, you will see a live version of the form that you can play with. I’ll talk about these controls more as we dive into creating a form that will gather the comment data.
<html>
<head>
<title>Sample Form</title>
</head>
<body>
<h1>Sample Form</h1>
<form action="showSampleForm.php?id=0" method="POST">
<p>Textarea: <textarea name="Textarea" rows="1" cols="40"></textarea> </p>
<p>Select:
<select name="Selection" value="">
<option value="">None</option>
<option value="1">Selection 1</option>
<option value="2">Selection 2</option>
<option value="3">Selection 3</option>
</select></p>
<p>Checkbox: <input type="checkbox" name="Checked" value="Yes"></p>
<p>Radio: Radio 1<input type="radio" name="Radio" value="Radio1" checked>Radio
<input type="radio" name="Radio" value="Radio2"></p>
<p><input type="submit" value="Update"> <input type="reset" value="Clear"></p>
</form>
</body>
</html>
Since PHP has built in support for post variables, you can just access the form data directly in the target form. The following page will read the input provided in the form.
<html>
<head>
<title>Sample Form Output</title>
</head>
<body><h1>Sample Form Output</h1>
<&php
print “<p>Textarea: $Textarea</p>”;
print “<p>Select: $Selection</p>”;
print “<p>Checkbox: $Checked</p>”;
print “<p>Radio: $Radio</p>”;
&>
</body>
</html>