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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:40:19+00:00 2026-05-26T11:40:19+00:00

I am unable to make Zend_Validate_EmailAddress show only 1 error message when the user

  • 0

I am unable to make Zend_Validate_EmailAddress show only 1 error message when the user enter invalid email address. The code is

$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email: ')
    ->addFilter('StringTrim')
    ->addFilter('StripTags')
    ->addValidator('EmailAddress',true, array(... error msgs ...))
    ->addValidator(new Zend_Validate_Db_NoRecordExists(array( ... db + table + col details ... ),true, array(... error msgs ...)))
    ->setRequired(true);
$this->addElement($email);

And when user enter invalid email like user@email (without the tld) it show multiple errors like

'email' is no valid hostname for email address 'user@email'  
'email' does not match the expected structure for a DNS hostname  
'email' appears to be a local network name but local network names are not allowed  

I can’t use addErrorMessage('...') as I need to display different message for invalid email and for email already exists in database. So any idea how to make EmailAddress validation return only 1 error message.

  • 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-26T11:40:20+00:00Added an answer on May 26, 2026 at 11:40 am

    To me, the problem is not that the messages are overly technical for the average user: that’s really a side issue that can be handled by overriding the individual message templates.

    For me, the fundamental issue is that this validator inherently returns multiple messages and we only want a single message.

    I have always had to resort to sub-classing the standard validator:

    class PapayaSoft_Validate_EmailAddress extends Zend_Validate_EmailAddress
    {
        protected $singleErrorMessage = "Email address is invalid";
    
        public function isValid($value)
        {
            $valid = parent::isValid($value);
            if (!$valid) {
                $this->_messages = array($this->getSingleErrorMessage());
            }
            return $valid;
        }
    
        public function getSingleErrorMessage()
        {
            return $this->singleErrorMessage;
        }
    
        public function setSingleErrorMessage($singleErrorMessage)
        {
            $this->singleErrorMessage = $singleErrorMessage;
            return $this;
        }
    }
    

    Then usage is as follows:

    $validator = new PapayaSoft_Validate_Email();
    $validator->setSingleErrorMessage('Your email is goofy');
    $element->addValidator($validator, true);
    

    Alternatively, using the short form, you need to add a new namespace prefix for validators so that the short key “EmailAddress” gets picked up from the new non-Zend namespace. Then:

    $element->addValidator('EmailAddress', true, array(
        'singleErrorMessage' => 'Your email is goofy',
    ));
    

    Note: While the question noted by @emaillenin is similar, the accepted answer there does not actually fulfill your requirements. It does set a single error message for the field, but it sounds like you need to have separate messages coming from the two validators (one for email-format, the other for email-already-exists). For that, it seems to me that you need to change the behavior of the EmailAddress validator itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unable to make sense of how and why the following code segments
Please see my code below. I am unable to make SetGravity work. How come?
C++ is unable to make a template out of a typedef or typedef a
Error: Unable to read data from the transport connection: A blocking operation was interrupted
I'm unable to make my pictureboxes to be shown on form. Am i doing
I have been unable to make a successful connection to my SQL Server (2005)
I am unable to make it circular on iphone CGPoint addLines[] = { CGPointMake(10.0,
After loading updatepanel through Timer, i am unable to make any async request from
I am unable to make a php curl request with port number , without
The problem is, I am unable to make it a dimension with 800x600. In

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.