-- chinaski <[EMAIL PROTECTED]> wrote
(on Friday, 11 April 2008, 01:38 PM -0700):
> This seems simple, but I can't make it work (path issue). I'm experimenting
> with Zend_Form, and I want to add a custom validator to a form field.
>
> I have written the a test validator and saved it as follows:
>
> I have saved the file as /My/Validate/TestVal.php.
Is that on your include_path? Check that -- it's likely the issue.
The 'My/' directory should be at the same leve as your 'Zend/'
directory:
application/
controllers/
...
library/
Zend/
My/
Validate/
TestVal.php
If it is, then the code you show below should work; if not, then you
have an include_path issue.
>
> I have a script that builds the form:
>
> <?php
>
> class forms_ContactForm extends Zend_Form
> {
> public function __construct($options = null)
> {
> parent::__construct($options);
>
> $this->addElementPrefixPath('My_Validate','My/Validate/','validate');
>
> $testing = new Zend_Form_Element_Text('testing');
> $testing->setLabel('Title')
> ->setRequired(true);
>
> $validators = $testing->getValidators();
> $testval = array('validator' => 'TestVal');
> array_unshift($validators, $testval);
>
> $testing->setValidators($validators);
>
> //etc...
> }
> }
>
> This fails at $testing->setValidators with the following message...
>
> Error: Plugin by name My_Validate_TestVal was not found in the registry.
>
> How to get the custom validator attached to the element?
>
> Thanks.
>
> Sam
>
>
>
> --
> View this message in context:
> http://www.nabble.com/custom-form-validator-tp16628634p16628634.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/