Forms and Files
Chapter 8 · Tamil Nadu State Board
- 3 min read
- 6-question quiz
Every key point below shows the sentence from your textbook it comes from. How we check content
In short
This lesson explains how HTML forms collect information from users and how PHP receives and processes it. It compares POST and GET methods and describes client-side and server-side validation. It also introduces PHP functions for opening, reading, closing and writing files. These skills help web applications handle user input and files.
Written by AI from this lesson. How we check it
Key points
- HTML forms collect data from users and send it to a server through controls such as text inputs and checkboxes.
From your textbook
“These data are collected via HTML form controls like textbox, dropdown box and radio button”
- The form tag sets a method such as POST or GET and manages the controls in the form.
From your textbook
“Form tag is used to mention a method (POST or GET) and control the entire form controls”
- PHP uses $_POST and $_GET to collect submitted input and prepare a response.
From your textbook
“two PHP variables such as $_POST and $_GET collects the data and prepares the response accordingly.”
- Validation checks input submitted by a user and can happen in the browser or on the server.
From your textbook
“There are two types of Validation rules for HTML input field validation available in PHP.”
- PHP file handling tasks include opening, reading, closing, writing, appending and uploading files.
From your textbook
“PHP Open a File, PHP Read a File, PHP Close a File, PHP Write a File, PHP Appending a File and”
- PHP provides fopen(), fread(), fclose() and fwrite() for opening, reading, closing and writing files.
From your textbook
“The fwrite() function is used to write to a file.”
Formulas in this chapter
- Open a file$file_Object = fopen("FileName", "Read/WriteMode") or die("Error Message!");Explained here
- Read from a filefread($file_Object, filesize("FileName"));Explained here
- Close a filefclose($file_Object);Explained here
- Write to a filefwrite($myfile, $txt);Explained here
HTML Forms and Form Controls
HTML forms collect information from users. Form controls gather the information, and PHP can process it on the server.
Basic HTML form controls
- Text inputs include textboxes and text areas.
- Radio boxes let the user choose one value at a time.
- Checkboxes let the user choose more than one value.
- Buttons include Submit, Reset and Cancel buttons.
- File Select lets the user choose one file from the local machine to send to the server.
- The Form tag groups the controls and specifies a method, such as POST or GET.
The form's action attribute names the PHP file that receives the submitted information. Other form attributes can specify the result's target window and how the browser encodes data before sending it.
PHP Form Handling and Validation
After a user enters information and clicks Submit, the browser sends the values to the PHP file named in the form's action attribute. PHP uses $_POST or $_GET to collect the values and prepare a response for the user's browser.
POST and GET methods
| POST | GET |
|---|---|
| Sends input data in the request body of the client's HTTP request. | Sends input data through the URL as a query string, so the values are visible to the user after submission. |
Validation checks the information a user submits. Client-side validation happens in the browser before data is sent to the server. Server-side validation happens after submission, using a server-side programming language such as PHP.
Input checks described
- Name: must contain letters and white-spaces.
- Email: must contain @ and .strings.
- Website: must contain a valid URL.
- Radio: at least one value must be selectable.
- Check Box: at least one value must be checkable.
- Drop Down menu: at least one value must be selectable.
A simple client-side check can use the required attribute in an HTML input tag. The browser asks the user to fill in the field if it is left empty.
PHP File Handling
PHP can open, read, close, write to, append to and upload files. These tasks help web applications process files.
File handling functions
- fopen() opens a server file and takes the file name and the mode, such as Read/WriteMode.
- fread() reads from an open file. It uses the file object and the file size.
- fclose() closes an opened file.
- fwrite() writes to a file using the file object and the text to write.
$file_Object = fopen("FileName", "Read/WriteMode") or die("Error Message!");
$file_Object stores the opened file; "FileName" names the file; "Read/WriteMode" specifies how it is opened; die("Error Message!") runs if opening fails.
fread($file_Object, filesize("FileName"));
$file_Object is the open file object; filesize("FileName") specifies the file size.
fclose($file_Object);
$file_Object is the file object to close.
fwrite($myfile, $txt);
$myfile is the file object; $txt is the text to write.
Questions students ask
Short, direct answers to what students search for in this chapter.
What are HTML forms used for?
HTML forms collect information entered by users. Controls such as text inputs, checkboxes and radio boxes gather the values. The form sends those values to a server, where a PHP file can collect them and prepare a response.
What is the difference between POST and GET in PHP forms?
POST sends input data in the request body of the client's HTTP request. GET sends input data through the URL as a query string. With GET, the submitted values are visible to the user after the form is submitted.
What are client-side and server-side validation?
Client-side validation checks input in the browser before the data is sent to the server. It can use client-side scripts or the required attribute in an HTML input tag. Server-side validation checks the submitted data on the server using programming such as PHP.
Which PHP functions are used to open, read, close and write files?
PHP uses fopen() to open a file, fread() to read from an open file, fclose() to close a file and fwrite() to write to a file. The reading and closing functions use the file object obtained when the file is opened.
Practice
What is the main purpose of HTML form controls?
Exam questions
Practice questions with model answers. These are not from an official paper.
What is the main purpose of HTML form controls, and how is the data sent to the server?2 marks
They collect data from users using controls such as textboxes, dropdown boxes and radio buttons. The data is sent to the server using server-side programming such as PHP.
Explain one difference between POST and GET.2 marks
POST stores submitted input in the request body. GET sends input through the URL as a query string, so the input is visible to the user after submission.
Name the two types of validation and explain where each takes place.2 marks
Client-Side Validation takes place in the client's web browser, using client-side scripts or the required attribute. Server Side Validation takes place on the server after the data is submitted, using programming such as PHP.
Describe four PHP file handling functions and what they do.2 marks
fopen() opens a file, fread() reads from an open file, fclose() closes an opened file, and fwrite() writes to a file.
Watch out
- Do not confuse checkboxes with radio boxes: checkboxes allow multiple selections, while radio boxes allow one value at a time.
- Do not mix up POST and GET: POST uses the request body, while GET places input in the URL query string.
Still stuck on this lesson?
Get an AI answer grounded in your actual textbook — with the exact page reference.
Ask AI about this topic →