What this session is about
On this page you should (hopefully)...- Forms forms forms
- Types of element
- More (advanced) elements
Forms forms forms
Each of the objects within that dotted box to the right are called "Elements" or sometimes "Controls". They all allow you to enter information into the form, when you click the "Submit" button the information is then sent away to some magical place where it returns with something you want.
Okay, so I lied about the magical place bit, it just goes to the computer that's running the website where it thinks about it, does what it's told and you get the result. Sadly, looking at how to make your website think is very much outside of the scope of this page, to do that you need to learn something called "PHP" (Though you can also use Perl, CGI, ASP and any number of other cool acronyms). The purpose of this page is to teach you how to create a form, not how to process what comes off it.
A form itself is actually a tag and used like so...
<form action="targetPage.php" method="post" accept-charset="utf-8">
<!--
Elements go here!
-->
</form>
<!--
Elements go here!
-->
</form>
-
action="targetPage.php"
This tells the form which page to send the information to. In this example it's a fictional page called targetPage.php. This is a link just like the href from an <a> tag and you can use all that you learnt from the linking tutorial.
-
method="post"
This must be either "post" or "get". Sometimes web designers place them in uppercase as "POST" or "GET", it makes no actual difference. Post means that the information sent is hidden, Get means that the information sent is stuck into the URL of the page you are going to. The advantage of Get is that you can allow the user to alter the data really easily, Post allows you to send more data and also make it harder to edit.
-
accept-charset="utf-8"
This one, you really don't need to know about so feel free to skip it. Usually it'll not make any difference at all, it just tells the browser what character set you can use. If you're using this site to learn HTML then I'm going to go out on a limb and assume you 1) don't know what a character set is, 2) really don't care what a character set is and 3) really hope it's not important to know what a character set is. Good news, it's not important and you can probably get away with not including this.
You type stuff here
Lets look at putting in some basic elements for our forms.Text Fields
<input type="text" name="someName" value="" />
Finally the value, this is of use to you. The value determines the initial value of the field when you open the page, if it said value="Type here" then the text field would start with the words "Type here" in it when the page is opened.
If you are feeling adventurous you can add the size attribute. This alters the width of the box used, useful if you don't want it to be too big or too small. The one to the right of the paragraph above has a size of 15, it can fit 15 letters into it (approximately).
Submit Buttons
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
Checkboxes
<input type="checkbox" name="checkBox" value="check" />
Radio Buttons
They're like checkboxes except you can only select one at a time (sort of).
<input type="radio" name="radioset" value="value" />
More (advanced) elements
The following two elements are slightly more advanced that the previous ones so I put them at the end, it just seemed the logical thing to do.Select Menus
<select name="selectMenu">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
<option value="3">Item 4</option>
</select>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
<option value="3">Item 4</option>
</select>
<option value="1" selected="selected">Item 1</option>
Textareas
<textarea name="textArea" rows="4" cols="20"></textarea>
You might have noticed that the <textarea> has a closing tag. Anything within the opening and closing tags is the default value for the text field.
Congratulations, you can now make forms!


