0% found this document useful (0 votes)
10 views

Lecture 10 PHP Form Handling

Uploaded by

somaliyow17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lecture 10 PHP Form Handling

Uploaded by

somaliyow17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

PHP Form Handling

Somaville University

Eng.Islow

22.5.2025
Introduction

PHP web applications heavily rely on HTML


forms.
A website made entirely of HTML is static;
however, the HTML form component is a
useful tool for adding interaction and
displaying dynamic information.
Form handling features in PHP may verify
user-provided data prior to processing.

2
Form Handling: What Is It?

An HTML form is a collection of different


form controls, like text fields, checkboxes,
radio buttons, etc., that allow the user to
interact, enter, or select specific data.
This data can either be processed locally by
JavaScript (client-side processing) or sent to a
remote server for processing using server-side
programming scripts like PHP.
3
HTML Form

The <form> and </form> tags contain one or


more form control elements. Name, action,
and method are some of the properties that
define the form element.

4
Syntax:

<form [attributes]>
Form controls
</form>

5
Attributes of the HTML form
element
 Among the many attributes of the HTML form element, the
following are often necessary and specified:
1) Action:
 A string represents the URL that handles the form submission. Take
http://example.com/test.php, for instance. Use the PHP_SELF server
variable - to provide the for-data to the same PHP script that defines
the HTML form
<form action="<?
php echo htmlentities($_SERVER['PHP_SELF']); ?
>" method="post">

6
2- Enctype:

 The Enctype Attribute indicates how the form


data should be encoded prior to transmission
to the server. Potential values include -
 application/x-www-form-urlencoded- the
initial value.
a) multipart/form-data - If the form has <input>
elements with type=file, use this.
b) text/plain - Good for troubleshooting.
7
3-Method:

 Method Attribute is a string that specifies the HTTP method that


should be used to submit the form. The potential value of the
method attribute - are as follows:
1) post - The POST method; the request body is the form data
submitted.
2) get (default) - The action URL is attached with the GET; form
data is separated by a "?" When there are no negative impacts
from the form, use this strategy.
3) dialog - Closes the dialog and triggers a submit event upon
submission when the form is within a <dialog> without clearing
the form or sending data.

8
4-Name:

 The form's name. If there are many forms in a


single HTML page, the value must be distinct
and cannot be an empty string.

9
5-Target:

 After the form is submitted, the Target Attribute is a string that specifies where the
answer should be shown. One of the following should be the case:
a) _self (by default) - The current browsing context will be used when you load.
b) _blank - Enter a fresh, anonymous browsing environment.
c) _parent - Enter the current browsing context's parent.
d) _top - The top-level browsing context, which is an ancestor of the present one and
lacks a parent, is loaded by the command _top.
e) Thus, a standard HTML form in a PHP web application appears as follows:
<form name="form1" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?
>" method="POST">
<!-- Form controls go here -->
</form>

10
Form Elements
A variety of controls and components are
used in the design of an HTML form. These
controls allow the user to input data or
choose from the choices that are shown.
A few of the elements are explained here.

11
1- Input:

 A data field is represented by the input


element, which allows the user to enter
and/or modify data. The INPUT element's
type property controls the data. The
following sorts of input elements are
possible:
a) Text: A text box where one line of text may
be entered.
 Syntax: 12
b) Password:
A text field with one line that hides the
characters that are input.
Syntax:
<input type="password" name="pwd">

13
2)Radio:

 This kind creates a circular, clickable button


that may be in either the ON or OFF state. It
is often a component of a radio group of
buttons.

14
Example:

<input type="radio" id="male" name="gender"


value="Male">
<label for="male">Male</label><br>

<input type="radio" id="female" name="gende


r" value="Female">
<label for="female">Female</label><br>
15
Checkbox:
 A collection of zero or more values from a predetermined list is represented
by a rectangular checkable box.
 Example:
<input type="checkbox" id="cricket" name="sports[]" value="Cricket">
<label for="cricket">I enjoy playing Cricket</label><br>

<input type="checkbox" id="football" name="sports[]" value="Football">


<label for="football">I enjoy playing Football</label><br>

<input type="checkbox" id="tennis" name="sports[]" value="Tennis">

<label for="tennis">I enjoy playing Tennis</label><br>

Lecture 2 16
File:

The input type lets the user choose a file from


the client filesystem, generally to be uploaded
to the server, and produces a button with a
caption. The "multipart/form-data" enctype
property has to be specified on the form.
 Syntax:
<input type="file" name="file">

Lecture 2 17
6-Select

 The choose element represents a control for choosing from a list of


alternatives. Select Control's option property defines each choice. As an
example,
 Example:
<select name="subject" id="subject">
<option value="physics">Physics</option>
<option value="chemistry">Chemistry</option>
<option value="math">Mathematics</option>
<option value="english">English</option>

</select>

18
Questions

19

You might also like