当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > PHP 表单

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 表单


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1406 ::
收藏到网摘: n/a

The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
PHP $_GET 和 $_POST变量是用来获取表单中的信息的,比如用户输入的信息。


PHP Form Handling
PHP表单操作

The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.
在我们处理HTML表单和PHP表单时,我们要记住的重要一点是:HTML页面中的任何一个表单元素都可以自动的用于PHP脚本:

Form example:
表单举例:

<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>

The example HTML page above contains two input fields and a submit button. When the user fills in this form and click on the submit button, the form data is sent to the "welcome.php" file.
上述HTML页面包含了两个输入框[input field]和一个提交[submit]按钮。当用户将信息填写完毕并点击提交按钮时,表单的数据将被发送至“welcome.php”文件。

The "welcome.php" file looks like this:
“welcome.php”文件如下所示:

<html>
<body>
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>

A sample output of the above script may be:
上述脚本将输出下面这段结果:

Welcome John.
You are 28 years old.

The PHP $_GET and $_POST variables will be explained in the next chapters.
PHP $_GET 和 $_POST变量将在下一章作具体讲解。


Form Validation
表单有效性验证[Form Validation]

User input should be validated on the browser whenever possible (by client scripts (JavaScript)). Browser validation is faster and you reduce the server load.
用户输入的信息应该尽可能的通过客户端脚本程序(如:JavaScript)浏览器上验证;通过浏览器进行信息的有效性验证可以提高效率并减少服务器的下载压力。

You should consider using server validation if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.
如果用户输入的信息需要存进数据库,那么你必须考虑在服务器端进行有效性验证。在服务器上验证信息有效性的最好方法就是把表单信息发给当前页进行验证,而不是调到其他页面进行验证。通过上述方法,如果表单存在错误,用户可以直接在当前页获取错误信息。这使得我们更容易发现存在的错误信息。

评论 (1) 1 All

登陆 | 还没注册?