Home > Backend Development > PHP Problem > What are PHP forms for?

What are PHP forms for?

藏色散人
Release: 2023-02-27 14:22:01
Original
3731 people have browsed it

What are PHP forms for?

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>
Copy after login

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>
Copy after login

Output:

Welcome Bill
Your email address is Bill.Gates@example.com
Copy after login

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>
Copy after login

"welcome_get.php" is like this:

<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template