Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Forms are used everywhere in development to store data in the backend. In PHP, form variables defined in the context are linked to the form elements, and a post-action is created to submit the form in the storage. We will first see some elements that use form validation and deal with the security issue.
Let us create a form with the below-mentioned fields
Name
Must contain only letter and whitespaces and is required
Email
Must be in email format and is required
Profile Link
Should be a link
Message
No rule
Slot
One must be selected
Text Fields
The below code illustrates name, email, profile link, message fields as text input. To take multiple text input lines, one can use textarea and specify the lines of rows and columns they need.
The hacker injected an unwanted script into the page. Now he can exploit information from the site. As he gains access, the javascript code injected is capable to scrap out critical information of the user like passwords, files and card information.
How to avoid it?
Using htmlspecialchars($_SERVER[“PHP_SELF]) can handle such attacks. It works by converting quotations,brackets to HTML entities like " , >, <. Now if the hacker tries to inject his script. The code will get converted to HTML.
The GET method is used to send form data via the URL, making it visible in the browser’s address bar. It is generally used for retrieving data or when the form submission does not involve sensitive information. Parameters are appended to the URL in a query string.
In this example, the form data is sent via the URL, such as process.php?username=value.
PHP Post Form
The POST method is used to send form data to the server in the body of the HTTP request, making it invisible in the URL. It is more secure than GET and is typically used for submitting sensitive data such as passwords or large amounts of data.
In this example, the form data is sent to process.php but is not visible in the URL. The data can be accessed using $_POST in PHP.
Frequently Asked Questions
What is $_POST PHP form?
$_POST is a PHP superglobal array used to collect form data sent via the POST method. It allows secure data submission without displaying it in the URL.
What is $_GET and $_POST in PHP?
$_GET retrieves form data sent via the GET method (visible in the URL), while $_POST retrieves data sent via the POST method (hidden in the request body).
What is $_COOKIE in PHP?
$_COOKIE is a PHP superglobal array that stores data sent by the client’s browser via cookies. It allows data to persist between requests.
Conclusion
We went through setting up a form for validation and used htmlspecialchars to help eliminate exploits. In the next article, you will see how to create error messages, validations in email and much more.
You can take a look at our PHP archives section and see many more interesting topics related to it.
Live masterclass
Top GenAI Skills to crack 30 LPA+ roles at Amazon & Google
by Sumit Shukla
02 Feb, 2026
03:00 PM
Python + AI Skills to ace 30L+ CTC Data roles at Amazon
by Prerita Agarwal
01 Feb, 2026
06:30 AM
Top 5 GenAI Projects to Crack 25 LPA+ Roles in 2026
by Shantanu Shubham
01 Feb, 2026
08:30 AM
Zero to Data Analyst: Amazon Analyst Roadmap for 30L+ CTC
by Abhishek Soni
02 Feb, 2026
01:30 PM
Top GenAI Skills to crack 30 LPA+ roles at Amazon & Google
by Sumit Shukla
02 Feb, 2026
03:00 PM
Python + AI Skills to ace 30L+ CTC Data roles at Amazon