简体   繁体   English

PHP:需要有关使用 PHP v5.1.3 的服务器上的表单验证的建议

[英]PHP: Need advice on form validation on a server with PHP v5.1.3

I'm trying to learn how to do server-side validation on a web form using PHP.我正在尝试学习如何使用 PHP 在 Web 表单上进行服务器端验证。 I already have the client-side validation working through jQuery.我已经通过 jQuery 进行了客户端验证。 During my studies I read something about native validation filters added to PHP v5.2 that does much of the grunt work for form validation.在我的学习期间,我阅读了一些关于添加到 PHP v5.2 的原生验证过滤器,它为表单验证做了很多繁重的工作。 Unfortunately, I just learned that my office server is running PHP v5.1.3.不幸的是,我刚刚得知我的办公室服务器正在运行 PHP v5.1.3。 Ouch!哎哟! To make a long story short, we can not upgrade the PHP version.总而言之,我们不能升级 PHP 版本。 End of discussion.讨论完毕。

As a newbie to all of this, are there other readily available functions out there that would help me validate form input data for older versions of PHP that do just as good of a job?作为所有这一切的新手,是否有其他现成的功能可以帮助我验证旧版本 PHP 的表单输入数据,这些功能同样出色? I read something about HTML_QuickForm2, but I already have my form built in HTML5 (using a polyfill to help older browsers like IE8 validate HTML5 forms).我阅读了一些关于 HTML_QuickForm2 的内容,但我已经在 HTML5 中构建了我的表单(使用 polyfill 帮助像 IE8 这样的旧浏览器验证 HTML5 表单)。

Again, new to all this and looking to be nudged into the right direction so I can get this form validated as quickly as possible.同样,这一切都是新手,并希望被推向正确的方向,以便我可以尽快验证此表单。

As a starter, I would suggest you look into HTML5 -- by default, you have some (very) basic validation for certain field types ( email , tel , date ...).作为初学者,我建议您查看 HTML5 - 默认情况下,您对某些字段类型( emailteldate ...)有一些(非常)基本的验证。

Next, I would look into PHP's preg_match ;接下来,我将研究 PHP 的preg_match this will help you match inputs to certain strings.这将帮助您将输入匹配到某些字符串。 First step would be to start reading a few articles on PHP validation.第一步是开始阅读一些关于 PHP 验证的文章。 Here's an introductory article on the subject.这是有关该主题的介绍性文章。 Another good source, which requires some time and effort, would be to go straight to the source at php.net .另一个需要一些时间和精力的好资源是直接访问php.net上的源。

The native validation filters (assuming email primarily) could be replaced with a simple regular expression.本机验证过滤器(假设主要是电子邮件)可以用一个简单的正则表达式替换。 As for others, string length checks, is_numeric checks and regex for more complex stuff will do the trick.至于其他人,字符串长度检查、is_numeric 检查和更复杂的正则表达式将解决问题。

But really: upgrade that server (or install a secondary one).但实际上:升级该服务器(或安装辅助服务器)。 PHP 5.1 is just ancient. PHP 5.1 只是古老的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM