Experiment No.: 09: Title: Write A Program To Validate A Form Using PHP. Objectives
Experiment No.: 09: Title: Write A Program To Validate A Form Using PHP. Objectives
Experiment No.: 09
Title: Write a program to validate a form using PHP.
Objectives:
1. To learn form handling in php using get and post method.
2. To understand empty () & preg_match () functions in PHP.
Theory:
HTML forms are required to collect the data from user, customer, etc. The
HTML <form> tag is used to create a HTML form. The HTML form contains form elements.
Form elements are different types of input elements, like text fields, checkboxes, radio
buttons, submit buttons and many more.
Action Attribute-
It defines the action to be performed when the form is submitted. Normally,
the form data is sent to a web page on server when user clicks on submit button. If action
attribute is omitted, the action is set to the current page.
Method Attribute-
The method attribute specifies the HTTP method (GET or POST) to be used
when submitting the form data.
<form action=“script” method=“get”>
<form action=“script” method=“post”>
Notes-
POST has no size limitations & hence can be used to send large amounts of
data.
Form submissions with POST cannot be bookmarked.
Proper Validation of Form data is important to protect Form from hackers and
spammers. Mostly when Form is submitted, the Form data is sent with POST method.
What is $_SERVER[“PHP_SELF”]?
It is a super global variable that returns the filename of currently executing script. It
sends submitted Form data to page itself, instead of jumping to different page. In this case,
user will get error messages on same page as the Form.