Presentation on theme: "Forms Describe common uses of forms on web pages"— Presentation transcript:
1 Forms Describe common uses of forms on web pages Describe the elements used in formsCreate forms on web pages using the <form>, <input>, <textarea>, and <select> tagsCreate forms that provide additional accessibility features using the accesskey and tabindex attributesAssociate form elements and element groups using the <label>, <fieldset>, and <legend> tagsCreate custom image buttons and use the <button> tag to include more variety and richer content than the standard form buttonDescribe the features of CGIInvoke server-side processing to handle form dataFind free CGI resources on the Web
2 Overview of Forms Forms are used all over the Web to Types of forms: Accept informationProvide interactivityTypes of forms:Search form, Order form, Newsletter sign-up form, Survey form. Etc….A form is an XHTML element that is used to contain and organize other objects such as text boxes, check boxes, and buttons that can accept information from web site visitors.
3 Two Components of Using Forms 1. The XHTML form itself, which is the web page user interfaceand2.The server-side processing, called CGI for Common Gateway Interface, which works with the form data and sends , writes to a text file, updates a database, or performs some other type of processing on the server.
4 XHTML Using Forms <form> tag <input> tag Used to contain the form elements on a web pageContainer tag<input> tagUsed to configure a number of form elements including text boxes, radio buttons, check boxes, and buttonsStand alone tag<textarea> tagUsed to configure a scrolling text box<select> tagUsed to configure a select box (drop down list)<option> tagUsed to configure an option in the select box
6 XHTML <form> tag The form tag attributes:actionSpecifies the server-side program or script will process your form dataidIdentifies the formmethodget – default value, form data passed in URLpost – more secure, form data passed in HTTP Entity Bodyname
7 XHTML<input> tag Text box Used to accept text informationAttributes:type=“text”namesizemaxlengthvalue
8 XHTML<input> tag Password box Used to accept text information that needs to be hidden as it is enteredAttributes:type=“password”namesizemaxlengthvalue
9 XHTML<input> tag Check box Used to allow the user to select one or more of a group of predetermined itemsAttributes:type=“checkbox”namecheckedvalue
10 XHTML<input> tag Radio Button Used to allow the user to select exactly one from a group of predetermined itemsEach radio button in a group is given the same name and a unique valueAttributes:type=“radio”namecheckedvalue
11 XHTML<textarea> tag Scrolling Text Box Used to configure a scrolling text boxAttributes:namecolsrowsvalue
12 XHTML<select> tag Select List Used (along with <option> tags) to configure a Select List .This form element is often referred to by several different names: Select List, Select Box, Drop-Down List, Drop-Down Box, and Option Box.Used to allow the user to select one or more items from a list of predetermined choices.Attributes:namesizemultiple
13 XHTML<option> tag Options in a Select List Used to configure the options in a Select ListAttributes:valueselected
14 XHTML<input> tag Submit Button Used to submit the formWhen clicked, it triggers the action method on the <form> tag and causes the browser to send the form data (the name and value pairs for each form element) to the web server.Attributes:type=“submit”namevalue
15 XHTML<input> tag Reset Button Used to reset the form fields to their initial valuesAttributes:type=“reset”namevalue
17 XHTML<input> tag Hidden form element This form element is not displayed on the web page.Hidden form fields can be accessed by both client-side and server-side scripting and are sometimes used to contain information needed as the visitor moves from page to page.Attributes:type=“hidden”namevalue
18 XHTML Using a Table to Format a Form <table border="0" width="75%"><tr><td align="right" width="10%">Name: </td><td><input type="text" name=CustomerName" size="30" /></td></tr><td align="right" width="10%"> </td><td><input type="text" name="Customer " /></td><td align="right" width="10%"> <input type="submit" value="Submit"></td><td><input type="reset"></td></table></form>
19 Questions1. You are designing a web site for a client who sells items in a retail store.They want to create a customer list for marketing purposes. Your client sells to consumers and needs a form that accepts their customer’s name and address.Would you recommend using two input boxes (one for the name and one for the ) or three input boxes (for the first name, last name, and address)? Explain your answer.
20 Questions2. You are designing a survey form for a client. One of the questions has 10 possible responses. Only one response can be selected per question. What type of form element would you use to configure this question on the web page?3. True or False. In a radio button group, the value attribute is used by the browser to process separate elements as a group.
21 XHTML Form Enhancements <label> tag The label tag<label> <input type="text" name="Customer " /><label>Or<label for=" " > </label><input type="text" name="Customer " id= " " />Container tagUsed to associate a text message with a form element
22 XHTML Form Enhancements <fieldset> & <legend> tags The fieldset tagContainer tagUsed to create a visual group of form elements on a web pageThe legend tagUsed to create a text label within the fieldset<fieldset><legend>Customer Information</legend>Name: <input type="text" name=CustomerName" size="30" /><br /><input type="text" name="Customer " /> </fieldset>
23 XHTML Form Enhancements tabindex attribute Attribute that can be used on form elements and anchor tagsNot supported by all browsersUsed to modify the default tab orderAssign a numeric value<input type="text" name="Customer " tabindex=”1” />
24 XHTML Form Enhancements accesskey attribute Attribute that can be used on form elements and anchor tagsNot supported by all browsersUsed to create a “hot-key” combination to place the focus on the componentAssign a value of a keyboard letterOn Windows use the CTRL and the “hot-key” to move the cursor<input type="text" name="Customer " accesskey="E" />
25 XHTML Form Enhancements <input> tag Image Button Used to submit the formWhen clicked, it triggers the action method on the <form> tag and causes the browser to send the form data (the name and value pairs for each form element) to the web server.Attributes:type=“image”namesrc
26 XHTML Form Enhancements <button> tag The button tagA container tagWhen clicked, its function depends on the value of the type attribute.Can contain a combination of text, images, and mediaAttributes:type=“submit”, type=“reset”, type=“button”namevalue
27 Questions Describe the purpose of the fieldset and legend tags. Describe the purpose of the accesskey attribute and how it supports accessibility.When designing a form, should you use the standard submit button, an image button or a button tag? Are these different in the way that they provide for accessibility? Explain your answer.
28 Server-Side Processing Your web browser requests web pages and their related files from a web server.The web server locates the files and sends them to your web browser.The web browser then renders the returned files and displays the requested web pages for you to use.
29 CGI Common Gateway Interface CGI is a protocol or standard method for a web server to pass a web page user's request (which is typically initiated through the use of a form) to an application program and accept information to send to the user.The web server typically passes the form information to a small application program that processes the data and usually sends back a confirmation web page or message.
30 Using CGIA web page invokes CGI by either an action method on a form or a hyperlink -- the URL of the server-side script or program is used. Any form data that exists is passed to the server-side CGI script.<form method=“post” action=“order.php”>The server-side script completes its processing and may create a confirmation or response Web page with the requested information.The web server returns this page to the web browser.
31 Languages that support CGI Programs or scripts that work with CGI can be written in many languages:PHPPerlCC++Active Server Pages (ASP)Java Server Pages (JSP)ASP.NETRuby on RailsAnd so on….
32 Steps in Utilizing CGIWeb page invokes CGI by a form post, action, hyperlink, etc...Any form information is sent in the form of name=value pairs to the web sever.2. Script on web server is executed3. Script accesses requested database, file, or process4. Web server returns web page with requested information or confirmation of action
33 Common Uses of Server-Side Scripting & CGI Search a databasePlace an order at an online storeSend a web page to a friendSubscribe to a newsletterAny type of server-side file or processing is a candidate for CGI
34 Sources of Free Server-Side Processing Many web host providers offer free scripts for their clients. Contact their support area or FAQ to learn more about their services.Some web sites that offer remotely hosted scripts (in return for displaying an ad).Microsoft FrontPage has Server Extensions that provide form processing: sending form data in s, saving form data in files, and saving form data in databases.
35 Questions Describe CGI. Code the form tag for a web page form that will use the post method to invoke a server-side script located at