Download presentation
Presentation is loading. Please wait.
Published byCori Watts Modified over 9 years ago
1
HTML F ORMS
2
F ORMS HTML forms are used to pass data to a server. An HTML form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements. The tag is used to create an HTML form. input elements.
3
T HE I NPUT E LEMENT The most important form element is the element. The element is used to select user information. An element can vary in many ways, depending on the type attribute. An element can be of type text field, checkbox, password, radio button, submit button, and more.
4
A TTRIBUTES FOR
5
T HE I NPUT E LEMENTS Text Fields: defines a one-line input field that a user can enter text into: First name: Last name:
6
T HE I NPUT E LEMENTS Password Field: defines a password field: Password: Radio Buttons: defines a radio button. Radio buttons let a user select ONLY ONE of a limited number of choices: Male Female
7
T HE I NPUT E LEMENTS Radio Buttons Attributes:
8
T HE I NPUT E LEMENTS Checkboxes defines a checkbox. Checkboxes let a user select ZERO or MORE options of a limited number of choices. I have a bike I have a car
9
T HE I NPUT E LEMENTS Checkbox Attributes:
10
T HE I NPUT E LEMENTS Drop downs: defines a drop down. defines the elements in drop down. Volvo Saab Fiat Audi
11
T HE I NPUT E LEMENTS Attributes for
12
O PTGROUP Group related options in the drop down list. Volvo Saab Fiat Mercedes
13
T HE I NPUT E LEMENTS Submit Button defines a submit button. A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input: Username:
14
T HE I NPUT E LEMENTS Reset Button defines a Reset button. It creates a button that automatically resets form controls to their initial values.
15
C REATING B UTTONS U SING THE E LEMENT The element is a more recent introduction that allows you to specify what appears on a button between an opening tag and a closing tag. So you can include textual markup or image elements between these tags. Submit I want to start again
16
F IELD SETS Group related elements in a form Gives the caption to the fieldset. Personal information: Name: E-mail: Date of birth:
17
T EXT A REA defines the area for text e.g. for comments You can define the area using the rows and columns attributes
18
C REATING L ABELS FOR C ONTROLS AND THE E LEMENT User name For controls that do not have a label, you should use the element. This element does not affect the form in any way other than telling users what information they should be entering
19
T ABBING O RDER If you want to control the order in which elements can gain focus, you can use the tabindex attribute to give that element a number between 0 and 32767, which forms part of the tabbing order. Every time the user presses the Tab key, the focus moves to the element with the next highest tabbing order (and again, Shift+Tab moves focus in reverse order). The following elements can carry a tabindex attribute:
20
T ABBING O RDER E XAMPLE One Two Three Four Five Six Seven Eight Nine Ten
21
S ENDING F ORM D ATA TO THE S ERVER The method attribute can take one of two values, either get or post, corresponding to the HTTP methods used to send the form data. If the element does not carry a method attribute, then by default the get method will be used. If you are using a file upload form control, you must choose the post method (and you must set the enctype attribute to have a value of multipart/form-data).
22
HTTP GET When you send form data to the server using the HTTP get method, the form data is appended to the URL specified in the action attribute of the element. The form data is separated from the URL using a question mark. Following the question mark you get the name/value pairs for each form control. Each name/value pair is separated by an ampersand (&). One of the great advantages of passing form data in a URL is that it can be bookmarked. If you look at searches performed on major search engines such as Google, they tend to use the get method so that the page can be bookmarked.
23
HTTP GET D ISADVANTAGE The get method, however, has some disadvantages. Indeed, when sending sensitive data such as the password shown here, or credit card details, you should not use the get method because the sensitive data becomes part of the URL and is in full view to everyone (and could be bookmarked).
24
S ITUATIONS TO A VOID “G ET ” ❑ You are updating a data source such as a database or spreadsheet (because someone could make up URLs that would alter your data source). ❑ You are dealing with sensitive information, such as passwords or credit card details (because the sensitive form data would be visible as part of a URL). ❑ You have large amounts of data (because older browsers do not allow URLs to exceed more than 1,024 characters — although the recent versions of the main browsers do not have limits). ❑ Your form contains a file upload control (because uploaded files cannot be passed in the URL).
25
HTTP POST When you send data from a form to the server using the HTTP post method, the form data is sent transparently in what is known as the HTTP headers. While you do not see these headers, they are sent in clear text and cannot be relied upon to be secure (unless you are sending data under a Secure Sockets Layer, or SSL ). The only issue with using the HTTP post method is that the information the user entered on the form cannot be bookmarked in the same way it can when it is contained in the URL. So you cannot use it to retrieve a page that was generated using specific form data as you can when you bookmark a page generated by most search engines, but it is good for security reasons.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.