Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2008, 09:58 PM
Junior Member
 
Join Date: Apr 2008
Posts: 4
Default Zend_Form custom validator

I'm experimenting with Zend_Form right now, and am trying to integrate a custom validation routine on a form field.

I have created a file called TestVal.php and saved it in My/Validate/ to match this class name:

class My_Validate_TestVal extends Zend_Validate_Abstract
{
...

It has a single isValid method which does a silly test on its value and returns a boolean.

My difficulty is in calling this thing:

In the form controller, I have this code:
//add prefix to all elements
$this->addElementPrefixPath('My_Validate','My/Validate/','validate');


$testing = new Zend_Form_Element_Text('testing');
$testing->setLabel('Test Val')
->setRequired(true);

$testing->addValidator('TestVal');

$testing->setValidators($validators);

//etc...

Running this code generates this error:

Error: Plugin by name TestVal was not found in the registry.

Note that the My/ folder is underneath the application root and is in the include path.

Thanks for any assistance.

chinaski

Last edited by chinaski : 04-11-2008 at 11:29 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 11:38 PM
Junior Member
 
Join Date: Apr 2008
Posts: 4
Default Partial answer // another question

If I add the prefix to the element, it works, but to the form, it doesn't.

For example,

$testing = new Zend_Form_Element_Text('testing');
$testing->setLabel('Test Val')
->setRequired(true);

//new code
$testing->addPrefixPath('My','My/');

$testing->addValidator('TestVal');

$testing->setValidators($validators);

Works. Can anyone tell me why it doesn't work when I add it to form itself?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-12-2008, 06:18 AM
Junior Member
 
Join Date: Mar 2008
Posts: 8
Default

what is $validators content?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 04:14 PM
Junior Member
 
Join Date: Apr 2008
Posts: 4
Default $validators

The $validators was a cut-and-paste error and was not in my final form code (sorry about that).

Here is the form code that works:

$testing = new Zend_Form_Element_Text('testing');
$testing->setLabel('Test Value')
->setRequired(true);

$testing->addPrefixPath('My','My/');

$testing->addValidator('TestVal');

Adding the prefixPath to the element runs the custom validator perfectly, but adding it to the form as in the previous message it doesn't work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-16-2008, 07:56 PM
Junior Member
 
Join Date: Apr 2008
Posts: 4
Default solved

Solution found here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:56 PM.