Home >Backend Development >PHP Tutorial >What is a php form? How to create a php form (example)

What is a php form? How to create a php form (example)

不言
不言Original
2018-07-24 15:04:454835browse

The php form is an area containing form elements. You can create a form by using the ff9c23ada1bcecdd1a0fb5d5a0f18437 tag and inserting relevant form elements into it. Below I will give you a detailed analysis of how to create a form.

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. That is the current page;
The second 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 method selection:

##The get method is to pass the submitted data through a series of The (name-value) pair appended to the URL is sent to the receiving page. For example:

http://www.example.com/script.php?name=Homer&gender=M&age=35

Unfortunately, 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 you need to take an action (such as 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 separately.


Let’s create a simple form. Since this file does not contain php code, I saved the file with a (.html) suffix. Of course, it can also be used (.php) suffix.

<!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>

Such a form is ready. The final rendering is as follows:

Related recommendations:

What is a PHP form and form creation

How to build a PHP form?

The above is the detailed content of What is a php form? How to create a php form (example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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