Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

XII STD B1

(COMPUTER APPLICATIONS)

K. NOOR AHAMED, M.C.A.,


(COMPUTER INSTRUCTOR)
CHAPTER – 8
CONTENT:

 Introduction to HTML Forms

 PHP Basic Form Handling

 Basic PHP Form Validation


HTML FORMS IN PHP
 Forms are used to receive information from the user.
 Forms are commonly used to allow users to register on a Website, to
log in to a Website, to order a product, and to send feedback.
 The <form> tag is used to create a form.

 An HTML form starts with <form> and


ends with </form> tag.
 Forms contain many types of form
controls like Text Boxes, Radio
buttons, Check Boxes, Buttons and
Drop-down lists.
HTML FORM CONTROLS
 HTML Form Controls are used to collect data from the users and
send to the Server.

Send Data

Validate Data
CLIENT SERVER
HTML FORM CONTROLS
Text Input

Buttons
6
Radio Box
Check Box
File Select

Form Tag
TEXT INPUT
 It contains Text Box (Single Line Input) and Text Area
(Multiline Input) controls.

2
Text Box Text Area
RADIO BOX
 It is used to select only one option.

CHECK BOX
 It is used to select more than one option.

3
BUTTONS
 It contains Submit (Sends the data), Reset (Clear the
data) and Cancel (Reload the Page)
FILE SELECT
 It is used to select file from the Local Machine and send
to Server Machine.

FORM TAG
 It contains POST & GET method to
control the entire Form Controls in the
HTML file.
<form> EXAMPLE

Text Box
Radio Box
Check Box
Text Area
File Select
Buttons
</form>
QUESTIONS
1) _________ are used to collect the data from the users and send to the server.
Ans: HTML Form Controls

2) Which HTML Form Control is used to select only one option? Ans: Radio Box

3) Which HTML Form Control is used to select multiple options? Ans: Check Box

4) Which type of button is used to send the data to the server? Ans: Submit

5) Which type of button is used to clear the data? Ans: Reset

6) Which type of button is used to reload the web page? Ans: Cancel

7) Which tag is used to control the entire form controls in the HTML file?
Ans: Form Tag
8) Which HTML form control is used to select the file from the local machine and
send to the server machine? Ans: File Select
GET METHOD POST METHOD
1) It sends the data through URL 1) It sends the data through
address. Client’s HTTP request.
2) The input data is visible to the 2) The input data is not visible to
user. the user.
3) It sends limited data. 3) It sends unlimited data.

4) It is less secure. 4) It is more secure.

5) It is saved in the browser 5) It is not saved in the browser


history. history.
6) It can be bookmarked. 6) It cannot be bookmarked.

7) It uses $_GET variable. 7) It uses $_POST variable.


EXAMPLE
Test.html
<html>
<body>
<form action="http://localhost/welcome.php" method="POST">
Name: <input type="text" name="name"><br><br>
E-mail: <input type="text" name="email"><br><br>
<input type="submit" value="submit">
</form>
OUTPUT
</body>
</html>
welcome.php EXAMPLE
<html>
<body>
Welcome
<?php OUTPUT
echo $_POST["name"];
?>
<br><br>
Your email address is:
<?php
echo $_POST["email"];
?>
</body>
</html>
QUESTIONS

1) All input values are synchronized and sent to the server via ______
methods. Ans: Get & Post

2) Once the data reaches the server, Which PHP variables collects the
data and prepares the response accordingly? Ans: Get & Post

3) In which method, the input data sent to the server is stored in the
request body of the client’s HTTP request? Ans: Get

4) The input data sent to the server with POST method via URL
address is known as _____________. Ans: Query String
FORM VALIDATION
 Validation is a process of checking the input data
submitted by the user from client machine.

 Validation of HTML Form data is important to protect the


data from Hackers and Spammers.

1) Client Side Validation 2


2) Server Side Validation
TYPES OF VALIDATION 2

CLIENT SIDE VALIDATION SERVER SIDE VALIDATION

1)The input data validation 1)The submitted data


is performed on the validation is performed
Client Machine using on the Server Machine
Web Browser. using Web Server.
2) It uses Client Side 2) It uses Server Side
Scripts like HTML, CSS Scripts like PHP, ASP
and JavaScript. and JSP.
VALIDATION RULES
NAME (TEXT INPUT)  Should require letters and white-spaces

EMAIL (TEXT INPUT)  Should require @ and .strings

WEBSITE (TEXT INPUT)  Should require a valid URL

RADIO BOX  Must be selectable minimum one value

CHECK BOX  Must be checkable minimum one value

DROP DOWN MENU  Must be selectable minimum one value


CLIENT SIDE VALIDATION
 Before sending the data to Server Side Program (PHP), the programmer can
write validations from the browser in the client machine.

 For this validation, we have to add “required” attribute in HTML input tag.

HTML
<form action="welcome.php">
Username: <input type="text" name="name" required> OUTPUT
<input type="submit">
</form>
QUESTIONS
1) _____ is a process of checking the input data submitted by the
user from client machine. Ans: Validation
2) How many types of validations are there? Ans: 2 (two)
3) Which validation is performed in the Web Browser?
Ans: Client Side Validation
4) Which validation is performed in the Web Server?
Ans: Server Side Validation
5) Which validation is called as input data validation?
Ans: Client Side Validation
6) Which validation is called as submitted data validation?
Ans: Server Side Validation

You might also like