+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 14 of 14

Thread: Validating multiple sets of checkboxes as one

  1. #11
    ro88o is offline Junior Member
    Join Date
    Jan 2010
    Location
    UK
    Posts
    16

    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?

  2. #12
    maciek.231 is offline Member
    Join Date
    Feb 2009
    Location
    Poland
    Posts
    90

    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.

  3. #13
    ro88o is offline Junior Member
    Join Date
    Jan 2010
    Location
    UK
    Posts
    16

    Default

    Brilliant, that's worked a treat. Thanks alot for your help!

  4. #14
    maciek.231 is offline Member
    Join Date
    Feb 2009
    Location
    Poland
    Posts
    90

    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

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. Mssql store procedure - problem with multiple result sets
    By michalowskiego in forum Databases
    Replies: 0
    Last Post: 06-15-2010, 01:14 PM
  2. How to decorate checkboxes?
    By Marco Polo in forum Model-View-Controller (MVC)
    Replies: 0
    Last Post: 11-06-2009, 12:38 AM
  3. Align Zend form checkboxes
    By krapspark in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 04-05-2009, 07:45 AM
  4. best way to add checkboxes in partialloop of table
    By painkilla in forum Model-View-Controller (MVC)
    Replies: 0
    Last Post: 03-24-2009, 01:34 PM
  5. Processing Checkboxes
    By altergothen in forum General Q&A on Zend Framework
    Replies: 3
    Last Post: 12-30-2008, 03:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts