search
HomeBackend DevelopmentPHP TutorialWhat is a php form? How to create a php form (example)

The php form is an area containing form elements. You can create a form by using the

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 (

).

<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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor