php表单验证_PHP表单验证:简介

php表单验证

In previous articles I’ve looked at creating an accessible form using HTML. At the time I mentioned that there were two things we could not do, at least at that stage:

在以前的文章中,我研究了使用HTML创建可访问 表单 。 当时我提到至少在那个阶段我们不能做两件事:

  1. Make a form look pretty (solved with CSS for forms)

    使表单看起来很漂亮(使用CSS解决了表单问题 )

  2. Actually do anything with the form information.

    实际上使用表单信息做任何事情。

We can now solve the latter problem with PHP. But before we send the user’s submitted data anywhere, we must check that they have filled out our form correctly. This is known as “form validation”. (Not to be confused with HTML validation).

现在,我们可以使用PHP解决后一个问题。 但是,在将用户提交的数据发送到任何地方之前,我们必须检查他们是否正确填写了我们的表格。 这称为“表单验证”。 (不要与HTML验证混淆)。

On a professional website there are typically two “levels” of form validation. The first uses JavaScript or HTML5: as the user fills out the form, moving from one field to another, we check what they have entered, providing warnings on the page when entered data does not match the values we expect.

在专业网站上,通常有两个“级别”的表单验证。 第一种使用JavaScript或HTML5:当用户填写表单时,从一个字段移到另一个字段,我们检查他们输入的内容,并在输入的数据与我们期望的值不匹配时在页面上提供警告。

However, since both of these technologies are run client-side, and thus are both insecure and optional (i.e. the user can turn JavaScript off), it is typical to implement a second, server-side check of the data. This is usually done with PHP, and it is this part that we will do first.

但是,由于这两种技术都是在客户端运行的,因此都是不安全且可选的(即用户可以关闭JavaScript),因此通常需要对服务器进行第二次数据检查。 这通常是用PHP完成的,这是我们首先要做的部分。

There are three steps to validating a form with PHP:

使用PHP验证表单的步骤分为三个步骤:

  1. Check that the entered data is correct. If it is, jump to step 3. Otherwise, go to step 2.

    检查输入的数据是否正确 。 如果是,请跳至步骤3。否则,请跳至步骤2。

  2. Display the form again, preserving any information entered this far and highlighting where errors occur. Allow the user to correct any mistakes and submit the form again, returning to step 1.

    再次显示该表单,保留到目前为止输入的所有信息,并突出显示发生错误的位置。 允许用户纠正任何错误并再次提交表单,返回到步骤1。

  3. When all form data is correct, process it (enter it into a database, send it in an email, etc), and provide some indication to the user that the process is complete.

    当所有表单数据正确时,对其进行处理(将其输入数据库通过电子邮件发送等),并向用户提供一些指示,表明该过程已完成。

翻译自: https://thenewcode.com/183/PHP-Form-Validation-Introduction

php表单验证

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值