Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:28:20+00:00 2026-05-25T23:28:20+00:00

I’m trying to add a custom validator to a field. It should take into

  • 0

I’m trying to add a custom validator to a field. It should take into account the value of another field. E.g. field A should be at most B+50%.

I’ve made a class implementing Zend_Validate_Interface, but apparently Zend Form only sends in the value of the current field to the validator. How do I make the validator receive everything?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:28:21+00:00Added an answer on May 25, 2026 at 11:28 pm

    When you call isValid on a Zend_Form it will pass the all the data you passed to the method

    $form->isValid(array('a' => 1, 'b' => 2));
    

    Your custom validator will receive that whole array of raw values.

    Example Validator

    class My_Validator_TwoVals implements Zend_Validate_Interface
    {
        public function getMessages()
        {
            return array();
        }
        public function isValid($value)
        {
            print_r(func_get_args());
        }
    }
    

    Example Form

    $f = new Zend_Form;
    $a = $f->createElement('Text', 'a');
    $b = $f->createElement('Text', 'b');
    $b->addPrefixPath('My_Validator', '.', 'validate');
    $b->addValidator('TwoVals');
    $f->addElements(array($a, $b));
    
    $f->isValid(array('a' => 1, 'b' => 2));
    

    Output

    Array
    (
        [0] => 2
        [1] => Array
            (
                [a] => 1
                [b] => 2
            )
    )
    

    As you can see there was also a second argument passed to isValid, which is $context. And that contains the remaining values.

    An alternative would be to pass the second element to match against as an option to the Validator, e.g.

    class My_Validator_TwoVals implements Zend_Validate_Interface
    {
        protected $a;
        public function getMessages()
        {
            return array();
        }
        public function isValid($value)
        {
            var_dump($this->a->getValue());
        }
        public function __construct(Zend_Form_Element $a)
        {
            $this->a = $a;
        }
    }
    

    Setup

    $f = new Zend_Form;
    $a = $f->createElement('Text', 'a');
    $b = $f->createElement('Text', 'b');
    $b->addPrefixPath('My_Validator', '.', 'validate');
    $b->addValidator('TwoVals', false, array($a));
    $f->addElements(array($a, $b));
    
    $f->isValid(array('a' => 1, 'b' => 2));
    

    Will then print int(1). As you can see, we fetched that value through the form element’s API so anything you configured for validators and filters would be applied, e.g. it’s not the raw value. And you can also set it to another value, etc.

    Also have a look at Zend_Validate_Identical to learn how ZF implements checking of other form elements:

    • http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Validate/Identical.php
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.