PHP Codeigniter中的自定义验证-必填两个字段之一 [英] Custom Validation in PHP Codeigniter - one of two fields required

查看:63
本文介绍了PHP Codeigniter中的自定义验证-必填两个字段之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格有手机和电话区。我希望用户填写其中一个字段,或都不填写两个字段。

My form has a cellphone and a phone field. I want the user to fill either one of the fields, or both, but not neither.

我已经看到用其他语言编写的方法,但是我可以有关如何使用Codeigniter的一些建议?

I've seen ways to do it in other languages, but could I have some advice on how to do it with Codeigniter?

推荐答案

只需在客户端进行JS验证,并在服务器上进行PHP验证-side(或使用CI的表单帮助器)...无论如何,PHP应该看起来像这样:

Just do a JS validation on client-side, and PHP validation on server-side (or use CI's form helper)... Anyway, PHP should look something like this:

if ($_POST['cellphone'] == '' OR $_POST['phone' == '') {
// do stuff like make an notification, alert, etc... and take users back to the form
}

这篇关于PHP Codeigniter中的自定义验证-必填两个字段之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆