01 - Build Form Using HTML
01 - Build Form Using HTML
❖ Introduction
❖ Building Forms
❖ Summary
8-Mar-23
3
Introduction
8-Mar-23
4
Introduction
8-Mar-23
5
Introduction
❖ The creation of a form into which a user can enter the required details.
❖ Data is sent to the web server to be interpreted with some error checking.
❖ If there is any error, the form may be redisplayed with an error message.
❖ If the code is satisfied with the accuracy of the input, it takes some action:
8-Mar-23
6
Building forms
8-Mar-23
7
Building forms
8-Mar-23
8
Building forms
<html>
<head>
<title>Form Test</title>
</head>
<body>
<form method="post" action="formtest.php">
What is your name?
<input type="text" name="name">
<input type="submit">
</form>
</body>
</html>
HTML
8-Mar-23
9
Building forms
8-Mar-23
10
Input Types: Text
HTML
8-Mar-23
11
Input Types: Text
❖ Attributes:
❖ Name: an identifier attribute that’s used for sending data through the HTML form element
❖ Size: specifies the width of the box (in characters of the current font).
❖ Maxlength: specifies the maximum number of characters that a user is allowed to enter.
❖ Disabled: specifies that an input field should be disabled. A disabled input field is
unusable and un-clickable.
<html>
<body>
<form method="post" action="calc.php">
<pre>
Loan Amount <input type="text" name="principal">
Number of Years <input type="text" name="years" value="15">
Interest Rate <input type="text" name="interest" value="3">
</pre>
</form>
</body>
</html>
HTML
8-Mar-23
13
Label element
❖ Defines a label for many form elements and useful for screen-
reader user.
❖ Help users who have difficulty clicking on very small regions such
as checkboxes
❖ When the user clicks the text within the <label> element, it toggles the
checkbox.
8-Mar-23
14
Label element
❖ Attributes:
❖ for: should be equal to the id attribute of the <input> element to bind them
together.
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
HTML
8-Mar-23
15
Input Types: number
8-Mar-23
16
Input Types: number
<html>
<body>
<form method="post" action="login.php">
<label for="quantity">Quantity (between 1 and
5):</label><br>
<input type="number" id="quantity" name="quantity"
min="1" max="5" ><br>
</form>
</body>
</html>
HTML
8-Mar-23
17
Input Types: Password
HTML
8-Mar-23
18
Input Types: Password
<html>
<body>
<form method="post" action="login.php">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>
</body>
</html>
HTML
8-Mar-23
19
Input Types: Email
HTML
8-Mar-23
20
Input Types: Email
<html>
<body>
<form method="post" action="login.php">
<label for="email">Enter your email:</label><br>
<input type="email" id="email"
name="email"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
<input type="submit">
</form>
</body>
</html>
HTML
8-Mar-23
21
Input types: Checkbox
❖ When you want to offer number of options to a user, from which they
can select one or more items.
HTML
8-Mar-23
22
Input types: Checkbox
</form>
HTML
8-Mar-23
23
Input types: Radio
❖ All the buttons in a group must use the same name, so,
HTML
8-Mar-23
24
Input types: Radio
</form>
HTML
8-Mar-23
25
Input types: Date
HTML
8-Mar-23
26
Input types: Date
8-Mar-23
27
Input types: Datetime-local
HTML
8-Mar-23
28
Input types: Datetime-local
8-Mar-23
29
Input types: Month
HTML
8-Mar-23
30
Input types: Month
8-Mar-23
31
Input types: time
HTML
8-Mar-23
32
Input types: time
8-Mar-23
33
Input types: submit
HTML
8-Mar-23
34
Input types: submit
8-Mar-23
35
Form Handling
❖ When you enter form data and click the submit button, the form
data is sent to the webserver for processing
❖ So now it’s time to add some PHP code to process the data
submitted by the form.
❖ When you enter form data and click the submit button, the form data is sent
to the webserver for processing using GET or POST methods
❖ Post: sends all contents of a form with basically hidden headers (not easily visible to
users)
❖ Get: sends all form input in the URL requested using name=value pairs separated by
ampersands (&)
❖ E.g. process.php?name=trevor&number=345
❖ Assume a form contains one input text called "txtName" and the
form is submitted using the post method, invoking process.php.
❖ $_GET["txtName"].
❖ Information sent from a form with the GET method is visible to everyone
(all variable names and values are displayed in the URL).
❖ Information sent from a form with the POST method is invisible to others
(all names/values are embedded within the body of the HTTP request)
❖ Introduction
❖ Building Forms
❖ Summary
8-Mar-23
Questions