Documente Academic
Documente Profesional
Documente Cultură
WEB PROGRAMMING
MEMBERS:
VELASCO MAURICIO
BANAAG ARRIOLA
ARANETA SANTILLAN
FRANCISCO VALERIANO
AGUILAR DIVINA
CONTENTS
PHP FORMS
01 02 03 04 05
PHP FORMS FORM FORM FORM FORM
VALIDATION DIFFERENT REQUIRED COMPLETE
ELEMETS FIELDS
01
REPORTER:
PHP FORMS
PHP FORMS
GET and POST create an array which holds key/value pairs, where keys are the name of the
form controls and the values are the input data user. Both GET and POST method are
treated as _GET and _POST in PHP. These methods are superglobals, which means that
they are always accessible, and they can be accessed using any function, class or files.
The $_GET method is an associative array of variables passed to the current script via
the URL parameters.
The $_POST method is an array of variables passed to the current script via the HTTP
POST method. In this method the information is transferred in a hidden manner.
Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3
=> value3, ...)). This array holds key/value pairs, where keys are the names of the
form controls and values are the input data from the user. Both GET and POST are
treated as $_GET and $_POST. These are superglobals, which means that they are
always accessible, regardless of scope - and you can access them from any function,
class or file without having to do anything special.
$_GET is an array of variables passed to the current script via the URL parameters
$_POST is an array of variables passed to the current script via the HTTP POST
method.
02
REPORTER:
FORM VALIDATIONS
PHP FORMS
03
REPORTER:
FORM DIFFERENT
ELEMENTS
PHP FORMS
The Name, E-mail, Website are input elements. Input elements, in particular, used text
and submit values for its types attribute in order to create text fields and buttons. The
HTML code for these input elements are:
Radio button shows several options to the users from which the user may select one. Mostly, it
displays a circle next to each option, filling in the circle that is currently selected. Creating sets of
radio button in HTML is a matter of creating several input elements all with the type attribute of
“radio” and the identical name attribute. The Gender field is a radio button and the HTML code of
the form looks like this:
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
The text area is typically a large text field with multiple rows. To create a text area is through text
area element. The textarea element has three attributes – name, rows, and cols attribute. The
HTML code of the form is:
Comment: <textarea name="comment" rows="8" cols="80">Type your comments here...
</textarea>
There’s another element called list, which offers options from which the user might choose.
A list can be created using the select element, within which is nested option elements for
each option to appear. The select element has a name attribute giving the name for the
browser to use when identifying the selection when the form is submitted. The option
element has a value attribute for specifying what value to send when that option is selected,
and it has a select attribute which allows the HTML to specify which option is initially
selected.
The code follows:
Country: <select name="country">
<option value="php" selected="selected">Afghanistan</option>
<option value="albania">Albania</option>
<option value="algeria">Algeria</option>
</select>
04
REPORTER:
FORM REQUIRED
FIELDS
PHP FORMS
Here is a simple PHP script that checks the name for empty input and throws an error
message if the input is empty:
if (empty($_POST["name"])) {
$nameErr = "Please enter your name";
} else {
$name = test_input($_POST["name"]);
}
In the code above, $nameErr variable is added, this variable for error will hold error
messages for the required fields. An if else statement is also added for each $_POST to
check if the variable is empty. If it is empty, an error message will be stored in the
$nameErr variable, and if it is not empty, it sends the user input data through the
test_input() function.
To display the error message in the HTML form (this will be generated if the user tries to
submit the form without filling in the required fields) use the code below:
05
REPORTER:
FORM COMPLETE
PHP FORMS
To show the values in the input fields after the user hits the submit button, we add a little
PHP script inside the value attribute of the following input fields: name, email, and website.
In the comment textarea field, we put the script between the <textarea> and </textarea>
tags. The little script outputs the value of the $name, $email, $website, and $comment
variables.
Then, we also need to show which radio button that was checked. For this, we must manip
ulate the checked attribute (not the value attribute for radio buttons):
PHP COMPLETION
FORM EXAMPLE:
Here is the complete code for the
PHP Form Validation Example:
SUBMITTED TO:
MR. KENJI BELTRAN LAURENTE
WEB PROGRAMMIN-PROFESSOR