gpt4 book ai didi

php - Zend Form 添加错误信息

转载 作者:行者123 更新时间:2023-12-03 23:06:12 26 4
gpt4 key购买 nike

我用zend form注册了表格

$password = new Zend_Form_Element_Password('password');
$password->setLabel($this->_translate->_("Password:"))
->setRequired(true)
->addValidator('stringLength', true, array(4, 32));

$confirmPassword = new Zend_Form_Element_Password('confirmpassword');
$confirmPassword->setLabel($this->_translate->_("Confirm Password:"))
->setRequired(true);

我在 Controller 中控制密码和确认密码。如果密码和确认密码不匹配,则在确认密码文本框下添加错误消息。我怎样做?

最佳答案

在你的表单中覆盖 isValid

/**
* Validate the form, check passwords.
*
* @param array $data
* @return boolean
*/
public function isValid($data) {
$valid = parent::isValid($data);
if ($this->getValue('password') !== $this->getValue('password2')) {
$valid = false;
$this->password2->addError('Passwords don\'t match.');
}

return $valid;
}

关于php - Zend Form 添加错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1694136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com