What is the PHP form for?
PHP super global variables $_GET and $_POST are used to collect form data (form-data).
PHP - A simple HTML form
The example below shows a simple HTML form that contains two input fields and a submit button:
Example
<html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>
When the user fills out this form and clicks the submit button, the form data will be sent to a PHP file named "welcome.php" for processing. Form data is sent via the HTTP POST method.
To display the submitted data, you can simply echo all variables. The "welcome.php" file looks like this:
<html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo $_POST["email"]; ?> </body> </html>
Output:
Welcome Bill Your email address is Bill.Gates@example.com
The same result can be obtained using the HTTP GET method:
Example
<html> <body> <form action="welcome_get.php" method="get"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>
"welcome_get.php" is like this:
<html> <body> Welcome <?php echo $_GET["name"]; ?><br> Your email address is: <?php echo $_GET["email"]; ?> </body> </html>
The above code is very simple. However, the most important part was left out. You need to validate your form data to prevent vulnerabilities in your scripts.
Note: Please pay attention to security when processing PHP forms!
This page does not contain any form validators, it only shows us how to send and receive form data.
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of What are PHP forms for?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
