Home >Backend Development >PHP Tutorial >Getting Started with PHP: Form Creation and Basic Processing_PHP Tutorial
In order to make it easier to learn arrays later, a transition chapter is introduced here, which is the form. As for why, you will discover its beauty when you actually learn arrays.
================================================== ====================
Form: A form is an area containing form elements.
Form elements are elements that allow users to enter information in a form (such as text fields, drop-down lists, radio buttons, check boxes, etc.).
Forms are defined using the form tag (ff9c23ada1bcecdd1a0fb5d5a0f18437).
<form action="script.php" method="post"> </form>
As far as PHP is concerned, the most important attribute of the form tag is action, which specifies which page the form data will be sent to. If it is empty, it will be submitted to the page containing the form, which is the current page;
Second The first attribute is method, which specifies how to send data to the processing page. The two options (get and post) indicate the HTTP method to be used.
method selection:
The get method sends the submitted data to the receiving page through a series of (name-value) pairs appended to the URL. For example:
http://www.example.com/script.php?name=Homer&gender=M&age=35Unfortunately, the amount of data transferred via get is limited, and it is not very secure (because the data is visible).
Generally speaking, get is used to request information, such as a specific record in a database or the results of a search (searches almost always use get).
When an action needs to be taken (such as when updating a database record or sending an email), use the post method.
For these reasons, I generally use post, and if exceptions occur, I will point them out otherwise.
Let’s create a simple form. Since this file does not contain PHP code, I saved the file with a (.html) suffix. Of course, the (.php) suffix can also be used.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>简单的HTML表单</title> <style type="text/css"> label {font-weight: bold;color: #300ACC;} </style> </head> <body> <form action="demo1.php" method="post"> <fieldset><legend>在下面的表格输入您的信息:</legend> <p><label>姓名: <input type="text" name="name" size="20" maxlength="40" /></label></p> <p><label>邮箱地址: <input type="text" name="email" size="40" maxlength="60" /></label></p> <p><label for="gender">性别: </label><input type="radio" name="gender" value="M" /> 男 <input type="radio" name="gender" value="F" /> 女</p> <p><label>年龄: <select name="age"> <option value="0-29">30岁以下</option> <option value="30-60">30岁 到 60岁 之间</option> <option value="60+">60岁以上</option> </select></label></p> <p><label>评论: <textarea name="comments" rows="3" cols="40"></textarea></label></p> </fieldset> <p align="center"><input type="submit" name="submit" value="提交信息" /></p> </form> </body> </html>
This form is ready, and the final rendering is as follows:
================================================== ================================================== =