title: Clearing Validation Error Messages from a Zend Form Element
body: <p>I have a form element for capturing email addresses.  I am using <code>Zend_Validate_EmailAddress</code> on the element, and it generates error messages that aren't very user-friendly.</p>
  
  <p>My first step was to specify new messages that were more user-friendly, but some of the checks simply don't lend themselves to a user-friendly message.  I then tried to simply clear those messages after running <code>isValid()</code> on the form and specify my own, but none of the functions I've found will clear the messages.</p>
  
  <p>What I've tried and results</p>
  
  <ol>
  <li><code>setErrorMessages()</code> - Values set here seem to be ignored altogether</li>
  <li><code>clearErrorMessages()</code> - Seems to be ignored</li>
  <li><code>setErrors()</code> - Adds my message, but leaves the others intact</li>
  </ol>
  
  <p>This is the code that displays the errors in my custom view script:</p>
  
  <pre><code>&lt;?php if ($this-&gt;element-&gt;hasErrors()): ?&gt;
      &lt;?php echo $this-&gt;formErrors($this-&gt;element-&gt;getMessages()); ?&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>MY SOLUTION</strong></p>
  
  <p>I'm awarding <a href="https://stackoverflow.com/users/208809/gordon">Gordon</a> with the answer, because his solution is most complete, but I ended up using the <code>addErrorMessage()</code> function on the element <a href="https://stackoverflow.com/questions/1239719/in-a-zend-form-how-to-avoid-zend-validate-email-from-generating-multiple-errors">like this</a>:</p>
  
  <pre><code>$element-&gt;addValidator('EmailAddress', false, $this-&gt;_validate['EmailAddress'])
          -&gt;addErrorMessage("'%value%' is not a valid email address");
  
  $element-&gt;addValidator('Date', false, array('MM/dd/yyyy'))
          -&gt;addErrorMessage("Date must be in MM/DD/YYYY format");
  </code></pre>