Example Form
Mailing List Signup
Form Element & Attributes
A form cannot be inside another form. Form elements are like containers to hold form control elements.
Action Attribute.
'action' attribute. Provides URL location of the application or script that will be used to process a form. Popular languages for this are: PHP, ASP, ASP.NET, Ruby, JavaServer Pages, Python. From example:
Example Action Attribute
action="/mailinglist.php"
Method Attribute
'method' attribute. Specifies how information is sent to the server. A browser encodes the form information to send to the server.
The default method is GET. GET tacks on a question mark plus the encoded form data to the end of the URL of the action attribute. GET is preferable to allow users to bookmark the results of a form submission, like a search result.
The other method is POST. The browser sends a server request containing special headers followed by the data. Only the server should see the content, so it is the best method for sending secure information. POST is also preferable to send a lot of data or to upload files.
Examples
method="POST"
Form data being sent
fullname = Sally Strongarm
email = strongarm.com
Form data after encoding
fullname=Sally+Strongarm&email=strongarm%40example.com
Encoded data added to end of URL via GET method
http://www.bandname.com/mailinglist.phpname=Sally+Strongarm&email=strongarm%40example.com
'name' attribute. Essentially the 'variable name' for the piece of data to be sent in the form. User input creates the variable's value. The 'name' must match the variable name in the code being used in tandem with the form data. Normally required for inputs unless no value is being sent, such as for the 'submit' and 'reset' input types.
'label' element. Important for accessibility. Associates a form control with a 'label' or description. Can use the attribute 'for' to specify an id rather than defaulting to the contents. For form controls that come with multiple options, like radio, checkbox, or scroll menus, 'label' must be applied to each individual option.
'fieldset' element. Helps accessibility. Groups related form controls together within a form. Fieldsets can be nested with fieldsets.
'legend' element. Can be included in a 'fieldset' as a caption describing the fieldset's content.
'optgroup' element.
Exercise: Pizza Order Form
Black Goose Bistro | Pizza on Demand
Our 12" wood-fired pizzas are available for delivery. Build your custom pizza and we'll deliver it within an hour.