Presentation is loading. Please wait.

Presentation is loading. Please wait.

Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.

Similar presentations


Presentation on theme: "Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down."— Presentation transcript:

1 Forms Collecting Data CSS Class 5

2 Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down options Insert text area Add hidden field Add password field File upload field and submit button

3 What is a Form? A form is a page that collects data for some specified purpose An XHTML form is a section of a document that has normal content, markup, and special elements called "controls"

4 Forms Go to form links posted at blog (“form links”) Observe the following: What type of data is asked for? How the page is composed: header, body, footer Mixture of elements (dropdown windows, radio buttons, etc)

5 Controls Controls: are checkboxes, radio buttons, menus, etc) and labels on those controls Go to “ Tryit” links at blog and try checkboxes, radio buttons, etc

6 Forms form All content of form and form controls must be wrapped inside form Forms have two required attributes: action method

7 Forms What does the action do? –Action makes the “road” to the server that performs the action What does the method do? –Method tells the browser how to send the data. There are two ways

8 Forms form action action is the path to the page on the server that will process the form Written like this: <form action= “contact_action”|

9 Forms form method method instructs the browser about how it should send the data: get and post Written like this:

10 Forms get What is “get?” get sends the information as part of the URL as a query string URL visible on the action page will consist of the address of the page followed by a question mark and then the form data written like this:

11 Forms get Disadvantages of get: URL has a limited length Security Information can be altered by user Cannot send binary data Search engines use get because it can be saved as a bookmark or favorite

12 Forms post For forms where the information has any length, use post Browser sends the form data in the HTTP headers (the information it sends to the server when it connects) Any amount of data can be sent in a post get is default, recommended to use post

13 Text Box input Most common element is the “single line text field” input with required type attribute Looks like this: <input type=“text”

14 Text Box input input requires a type attribute the type attribute tells exactly which control is desired. Example: <input type=“text”

15 Text Box input When the browser sends info to server, it needs to associate the user-entered data with the form control into which it was entered, so every form control has a required name attribute

16 Text Box name attribute name may consist only of letters, numbers, dashes, and underscores Naming conventions (requirements of processing language, not XHTML: Begin with a letter, not a number Name may be case sensitive Check with developer of processing script for others Continuing… input tag always empty, so put “/”

17 Text Box form Set the visible width of the field: add size to the input tag:

18 Text Box form Limit the number of characters: –Set the length with the maxlength attribute, which does not need to be the same as size Looks like this:

19 Text Box form Prefill data using the value attribute:

20 Adding Labels label Apply two ways: 1.Wrap label text and input tag in the label tag: First Name: Use this when there is no code separating label from field

21 Adding Labels label 2. Associate them by7 add id attribute to the form field, then setting the label element’s for attribute to a value matching the id: First Name Use this when other code needs to appear between the label and the control.

22 Check Boxes & Radio Buttons check box radio Use when user selects from a list: –check boxes –radio buttons –select list Use input element Both require name (identical because the data can then be handled as a logical set)

23 Check Boxes & Radio Buttons check box radio Require a value Value should be unique to each button Value attribute allows you to set meaning of the check box or radio button

24 Check Boxes & Radio Buttons check box radio Adding pre-select Use checked=“unchecked” attribute to the tag Example:

25 Drop-Down List Drop-down lists are spacesavers Rely on two primary elements: select Option select defines the list as a whole and provides its name within select, there is a series of option tags

26 Drop-Down List option tags Each option tag has a value, which is the data to be sent to the server Between the opening and closing option tags is the text the user will see in the browser Alabama Alaska

27 Drop-Down List multiple select lists a single selection Create additional attributes with multiple Always has value of multiple Tells browser it should allow more than one selection size attribute determines number of options visible on screen Browser will automatically add scroll bar

28 Group Drop-Down Options optgroup Grouping elements within a long list Place in the select tag and will wrap around a set of option elements optgroup element takes a required label attribute Allows for insertion of a description of the group of options that follow

29 Group Drop-Down Options optgroup Looks like this:XHTML does not limit number of options in optgroups (just like select) Can’t nest subcategories Arkansas Illinois Indiana Iowa Kansas Michigan Minnesota Missouri Nebraska North Dakota Ohio South Dakota Wisconsin

30 Insert Text Area textarea To allow user to input large blocks of text –Example: craigslist textarea element Takes a required name attribute Size of box: –Default varies with browser –Accepts row and col to set size

31 Insert Text Area textarea Setting size of box looks like this. Note that because textarea is a container element, there is a closing tag Additional Comments:

32 Insert Text Area textarea Limiting input: without JavaScript, no way to limit the information into a textarea Some browsers restrict to 65,536 characters

33 Insert Text Area textarea Allowing user to mark up text: Use FCKEditor Implemented with both XHTML and JavaScript

34 Add a Hidden Field hidden For when designer needs to embed data that should not be editable by or visible to users Google hides preference for language in a hidden field named hl

35 Add a Hidden Field hidden Looks like this: –Use input, set the type attribute to hidden –name attribute is required –Provide value attribute representing data being embedded

36 Add a Password Field password Use input with a type of password Browser automatically replaces the text being inserted with asterisks Looks like this: Please create a password:

37 Add a File Upload Field file Consists of two parts: –Text field for the path to the file –Button that allows user to browse computer’s hard drive for file Use input field with type set to file Name required for file, of course

38 Add a File Upload Field file Designer issues: size and maxlength not supported Makes size of boxes different No control over Browse text Browsers only allow one file per upload field Looks like this: If you would like us to review a file, please upload it:

39 Add a File Upload Field enctype Also needed: –Add an additional attribute to the form tag: Enctype The default enctype is application/x- www-form-urlencoded, which makes browser send all text File needs to be sent as binary data, the rest can be sent as text, so add enctype and set its value to multipart/form-data Also set method to post

40 Add a File Upload Field enctype Looks like this: Select a file to upload:

41 Add a Submit Button submit Form complete, user now needs to send it Use input element with a type set to submit XHTML requires a name for the button Assure consistency across browsers by providing a value attribute Size of button determined by length of text but can be precisely controlled with CSS

42 Add a Submit Button submit Return or Enter key sending: –Browsers inconsistent in how this is handled vs. clicking the button –All browsers submit the form with Return and Enter but some do not submit the button’s name and value to the server –If using multiple submit buttons on a form, provide a unique name for each –Use server processing script to see which button was clicked, then do necessary processing

43 Other button types reset button reset Setting input type to reset creates a button that will clear form Use is not recommended button Setting input type to button creates a generic button with no default behavior With generic button, provide JavaScript code to instruct its function Often used for client-side scripting


Download ppt "Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down."

Similar presentations


Ads by Google