Cs-344: Web Engineering: Dr. Mehdi Hussain
Cs-344: Web Engineering: Dr. Mehdi Hussain
2
3
Outline
• action="url“ (required)
• Specifies where to send the data when the Submit button is clicked
• method=“GET" (default)
• Form data is sent as a URL with ?form_data info appended to the
end
• The length of a URL is limited (about 3000 characters)
• Never use GET to send sensitive data! (will be visible in the URL)
• Useful for form submissions where a user wants to bookmark the
result
• Better for non-secure data, like query strings in Google (Example)
The <form> element
• method="post"
• Form data is sent in the body of the URL request
• Through POST, form data contains sensitive or personal information
• POST has no size limitations, and can be used to send large
amounts of data.
• Form submissions with POST cannot be bookmarked (Example)
• target="target"
• Tells where to open the page sent as a result of the request
• target= _blank means open in a new window
• target= _top means use the same window
The <input> element
• Most, but not all, form elements use the input tag, with a
type="..." attribute to tell which kind of element it is
• type can be text, checkbox, radio, password, hidden, submit,
reset, button, file, or image
A password field:
<input type="password" name="textfield3" value="secret">
• Note that two of these use the input tag, but one uses textarea
Buttons through input tag
• A submit button:
<input type="submit" name="Submit" value="Submit">
• A reset button:
<input type="reset" name="Submit2" value="Reset">
• A plain button:
<input type="button" name="Submit3" value="Push Me">
• If two or more radio buttons have the same name, the user can only
select one of them at a time
• This is how you make a radio button “group”
• If you ask for the value of that name, you will get the value specified for
the selected radio button
• type: "checkbox“
• Note: While the value is not displayed to the user in the page's content, it is
visible (and can be edited) using any browser's developer tools or "View
Source" functionality. Do not use hidden inputs as a form of security!
13
Dropdown Lists
• The <select> element defines a drop-down list:
14
Activity
15
Outline
• Project timeline
• New Input types in HTML 5
• New Form elements in HTML 5
16
• <form>
Select your favorite color:
<input type="color" name="favcolor">
</form>
18
Input Type Date
• The <input type="date"> is used
for input fields that should contain a
date.
• You can also add restrictions to
dates (min and max)
• <form>
Birthday:
<input type="date" name="bday">
</form>
19
Input Type Datetime-local
• The <input type="datetime-local"> specifies a date and
time input field, with no time zone.
• <form>
Birthday (date and time):
<input type="datetime-local" name="bdaytime">
</form>
20
Input Type Email
• The <input type="email"> is used for input fields that
should contain an e-mail address.
• Some smartphones recognize the email type, and adds
".com" to the keyboard to match email input.
• <form>
E-mail:
<input type="email" name="email">
</form>
21
Input Type Month
• The <input type="month"> allows the user to select a
month and year.
• <form>
Birthday (month and year):
<input type="month" name="bdaymonth">
</form>
22
Input Type Number
• The <input type="number"> defines a numeric input
field.
• The following example displays a numeric input field,
where you can enter a value from 1 to 5:
• <form>
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
</form>
23
Input Restrictions
24
Numeric Restriction example
25
Other inputs
Type Code Preview
Range <input type="range>
Search <input type="search“>
Telephone <input type="tel“>
Time <input type="time“>
URL <input type=“url“>
Week <input type=“week“>
Examples
26
New Form Elements
• <datalist> Defines pre-defined options for input controls
• <keygen> Defines a key-pair generator field (for forms)
• <output> Defines the result of a calculation
27
28
29
HTML5 <output> Element
• The <output> element represents the result of a
calculation (like one performed by a script).
• Perform a calculation and show the result in an <output> element:
30
31
Example: autocomplete
33
Example: form
34
Example: formaction
35
Example: formenctype
Example: pattern
37
Example: placeholder
38
Activity
39
Can we design?
Further Reading
• W3Schools is a good and widely used resource
to learn HTML
• https://www.w3schools.com/html/html_forms.asp
• https://www.w3schools.com/html/html5_intro.asp