How can I output HTML from a Zend Validation Error?
Asked Answered
Z

2

7

I am trying to get this Zend Validator to output a link that goes to a resetpass form. At the moment, it is simply outputting the HTML as text. Any ideas on how to get it writing to the page as HTML?

Thanks!

Here's my code:

    protected $_authAdapter;
    protected $_messageTemplates = array(
            self::NOT_UNIQUE => 'This email has already been registered! <a href=\'/user/resetpass/\'>Need to reset your password?</a>'
    );

    public function isValid($value, $context=null)
    {
        $value = (string) $value;
        $users = new Users(array('db' => 'tdb'));
        if($users->userExists($value)){
            $this->_error(self::NOT_UNIQUE);
            return false;
        }
        return true;
    }
}
Zygophyte answered 2/5, 2009 at 5:54 Comment(1)
For checking if a value exists in a database, there is already Zend_Validate_Db_NoRecordExists and Zend_Validate_Db_RecordExists by the way.Linc
S
5

You have to pass the configuration option 'escape' = false to the Zend_Form_Decorator_Errors().

Mostly this one is loaded automatically so then you have to request it.

$zendelement->getDecorator('Zend_Form_Decorator_Errors')->setOption('escape', false);
Skink answered 2/5, 2009 at 10:55 Comment(1)
This does not work for me in ZF 1.12Rendition
A
6

On version 1.7 this is the correct way of accessing the validator and disable the escaping:

$zendelement->getDecorator('Errors')->setOption('escape', false);

Aeolis answered 10/3, 2010 at 16:18 Comment(1)
this works for me. I'm using ZF 1.12Rendition
S
5

You have to pass the configuration option 'escape' = false to the Zend_Form_Decorator_Errors().

Mostly this one is loaded automatically so then you have to request it.

$zendelement->getDecorator('Zend_Form_Decorator_Errors')->setOption('escape', false);
Skink answered 2/5, 2009 at 10:55 Comment(1)
This does not work for me in ZF 1.12Rendition

© 2022 - 2024 — McMap. All rights reserved.