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 3991296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:35:55+00:00 2026-05-20T06:35:55+00:00

I am trying to write a validator in Zend framework. The validator queries the

  • 0

I am trying to write a validator in Zend framework.

The validator queries the database to check if a particular record exists, this query uses a where clause. The value for the where clause is specified by another field on the form, so how do I pass this value into the validator?

This is how I add my validator:

$adgroup_name->addValidator(new Generic_ValidateUniqueAdGroupName() ); break;

Within my validator I have:

// Query which gets an array of existing ad group names in db
$q = Doctrine_Query::create()
->select('a.name')
->from('AdGroup a')
->where('a.name = ?', $value)
->andWhere('a.campaign_id = ?', $campaign_id);      
$adgroup_names_result = $q->fetchOne(array(), Doctrine::HYDRATE_ARRAY);     

How do I pass in $campaign_id? I’ve tried the following and it doesn’t work:

$adgroup_name->addValidator(new Generic_ValidateUniqueAdGroupName($campaign_id) ); break;
  • 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-20T06:35:55+00:00Added an answer on May 20, 2026 at 6:35 am

    The principle is the same as used in “confirm password” validators. You need the value of another element in the form in the field when the form is submitted. That’s why attempting to instantiate the validator with the campaign_id is not working: the value of $campaign_id is not yet set.

    When an element calls isValid() on its validators, it passes a second parameter called $context that is filled with an array of submitted form values. So your isValid() method in your validator should look something like this:

    public function isValid($value, $context = null)
    {
        $campaign_id = $context['campaign_id'];
        // Now build your query using $value - from the element to which this 
        // validator is attached - and the $campaign_id provided by the context.
        // And, of course, return true/false as required.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying write a query to find records which don't have a matching record
I've been trying to build a pepXML to mzIdentML converter and using this validator
I'm trying to write a unit test for the database layer that validates the
I am trying to write a Less than validator for jQuery. I want to
I'm trying to write a validation to check that an Object instance can be
I'm trying to write a xml schema that will validate this piece of xml:
I'm trying to write a reasonably permissive validator for names in PHP, and my
i am trying to write a validator which could validate the bunch of commas
I trying to write a xsd validator utility using MSXML 6.0. All is fine
I'm trying to write a custom ASP.NET field validator which makes sure the input

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.