Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework Components > Core Infrastructure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old 02-05-2010, 10:46 AM
Junior Member
 
Join Date: Jan 2010
Location: UK
Posts: 15
Default

Yep it's a public function - the API shows 'boolean isValid (mixed $value)' so I can't pass an extra argument in can I?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 02-05-2010, 05:34 PM
Member
 
Join Date: Feb 2009
Location: Poland
Posts: 83
Default

Ah, one small thing. The second argument should have a default value, so that it is compatible with the interface - that is, so that you can call it with just one argument. So:
Code:
public function isValid($value, $formData = null) {...}
That should work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 02-08-2010, 11:20 AM
Junior Member
 
Join Date: Jan 2010
Location: UK
Posts: 15
Default

Brilliant, that's worked a treat. Thanks alot for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 02-08-2010, 09:36 PM
Member
 
Join Date: Feb 2009
Location: Poland
Posts: 83
Default

You're welcome. Anyway, I came across a blog post about the topic of validating multiple elements with dependencies between them. The author has a point, stating that it would be logical that if validation depends on more than an element itself, it should be done in the form. This is some sample code to check two password fields ("password" and "repeat password" must be the same):
Code:
class MyForm extends Zend_Form {

    //...

    public function isValid($data) { 
        $ret = parent::isValid($data); 
  
        if ($this->password->getValue() != $this->repeatPassword->getValue()) { 
            $this->repeatPassword->addError("Passwords do not match"); 
            return false; 
        } 
        return $ret;
    }
}
Source: Zend_Form: walidacja rozbudowanych formularzy - Zend Framework, PHP, Webdesign :: MateuszTymek.pl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB 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:25 PM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0