使用来自另一个子表单的值进行相同的验证
我已将一个长的一页表单分成多个子表单,预计它将在项目生命周期的后期拆分为多页表单。我在使用下面的相同验证器中的令牌变量时遇到问题。
从 Application_Form 对象:
$authorizedIndividual = new Zend_Form_SubForm();
// .. authorizedName text element setup here
$termsAgree = new Zend_Form_SubForm();
// Add termsAgree
$termsAgree->addElement('text', 'termsAgree', array(
'label' => 'By typing your name in the preceding field, you, as the authorized individual agree to etc. etc. etc.',
'class' => 'termsAgree',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('validator' => 'Identical', true, $authorizedIndividual->authorizedName )
)
));
I've separated a long one page form into subforms anticipating it will be split into a multipage form later in the project lifecycle. I'm having trouble with the token var in the Identical validator below.
From the Application_Form object:
$authorizedIndividual = new Zend_Form_SubForm();
// .. authorizedName text element setup here
$termsAgree = new Zend_Form_SubForm();
// Add termsAgree
$termsAgree->addElement('text', 'termsAgree', array(
'label' => 'By typing your name in the preceding field, you, as the authorized individual agree to etc. etc. etc.',
'class' => 'termsAgree',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('validator' => 'Identical', true, $authorizedIndividual->authorizedName )
)
));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,
Zend_Validate_Identical
仅适用于字符串标记。通过此令牌从上下文(isValid 数据)检索该值。解决问题的最简单方法是在 isValid 方法中定义令牌并使用
authorizedName
值。As far as I know,
Zend_Validate_Identical
only works with string tokens. The value is retrieved from the context (isValid data) via this token.The easiest solution to your problem is to define the token within the isValid method and use the
authorizedName
value instead.