title: How to pass in a parameter to a custom Zend validator?
body: <p>I am trying to write a validator in Zend framework.</p>
  
  <p>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?</p>
  
  <p>This is how I add my validator:</p>
  
  <pre><code>$adgroup_name-&gt;addValidator(new Generic_ValidateUniqueAdGroupName() ); break;
  </code></pre>
  
  <p>Within my validator I have:</p>
  
  <pre><code>// Query which gets an array of existing ad group names in db
  $q = Doctrine_Query::create()
  -&gt;select('a.name')
  -&gt;from('AdGroup a')
  -&gt;where('a.name = ?', $value)
  -&gt;andWhere('a.campaign_id = ?', $campaign_id);      
  $adgroup_names_result = $q-&gt;fetchOne(array(), Doctrine::HYDRATE_ARRAY);     
  </code></pre>
  
  <p>How do I pass in $campaign_id? I've tried the following and it doesn't work:</p>
  
  <pre><code>$adgroup_name-&gt;addValidator(new Generic_ValidateUniqueAdGroupName($campaign_id) ); break;
  </code></pre>