基于php网站建设论文,培训机构还能开吗,域名一定要备案才能用吗,网站建设包含专业我正在处理包含用户数据,特别是电话号码字段的表单.通常不需要电话号码,因此模型中唯一的验证规则是usphone规则.但是,如果用户正在提交此表格,则电话号码变得必不可少.我以为我可以在运行中简单地添加验证规则,设置模型并调用validates方法,但是我做错了或者没有按我预期的方式…我正在处理包含用户数据,特别是电话号码字段的表单.通常不需要电话号码,因此模型中唯一的验证规则是usphone规则.但是,如果用户正在提交此表格,则电话号码变得必不可少.我以为我可以在运行中简单地添加验证规则,设置模型并调用validates方法,但是我做错了或者没有按我预期的方式工作.在我的控制器中# Update a few validation rules that are specific to this context$this-Proposal-Requestor-validate[phone_number][notempty] array(rule notEmpty,message Please enter a phone number so can can contact you with any questions about the work.,allowEmpty false,required true,);$validationErrors array();$this-Proposal-Requestor-set( $this-data[Requestor] ); # $this-data[Requestor][phone_number] only (no other requestor data)if( !$this-Proposal-Requestor-validates( array( fieldList array( phone_number ) ) ) ) {$validationErrors[Requestor] $this-Proposal-Requestor-validationErrors;}即使我将电话号码字段留空,也不会报告任何错误.在这种情况下,我向用户请求的唯一信息是他们的电话号码,因此其余的请求者数据为空,但是我尝试合并其余的用户数据,但得到的结果相同.如果删除fieldList选项,则会在其他字段上收到错误消息,但空电话号码上仍然没有任何提示.知道我在这里缺少什么吗我已经忙了好几个小时了,只是找不到正确的答案.谢谢.解决方法:解决方案最终是双重的我在phone_number字段上已有规则,将值强制为美国电话号码.该规则还将allowEmpty设置为true,并且将false设置为false.我想捕获一个空值,以便显示特别精确的消息.我必须更新现有规则以翻转allowEmpty和必需值,还必须添加一个新规则,其最后一个值设置为true.添加到我的控制器操作中的最终更改如下所示$this-Proposal-Requestor-validate Set::merge($this-Proposal-Requestor-validate,array(phone_number array(notempty array(rule notEmpty,message Please enter a phone number so can can contact you with any questions about the work.,allowEmpty false,required true,last true,),usphone array(allowEmpty false,required true,),)));我不记得我是否验证过,鉴于新规则的最后一个值,对现有的usphone规则进行更改绝对是必要的,但是这种组合可以正常工作.标签cakephp-1-3,cakephp,php来源 https://codeday.me/bug/20191202/2086533.html