5
votes

I need change all standart error message on my message in Zend_Element_Text when i use validator('EmailAddress') this validator trows several differnt message.

  • Value is required and can't be empty
  • '' is no valid email address in the basic format local-part@hostname

When i set options setErrorMessage('some my error text') it string shows on any error several times.

the error looks like

  • some my error text
  • some my error text

What the best way to solve this problem ?zf version 1.10.3

2
I tried cleaning up your question but for the life of me I can't figure out what you mean by '...this validator trows differnt message and standatr options setErrorMessage writen as much as this element(1,2,3 same message)' - Mike B
I see that before but its unclear wher i can see existing static variables like Zend_Validate_GreaterThan::NOT_GREATER ? - Alexandr

2 Answers

3
votes

The following should cover all error messages for Zend_Validate_EmailAddress

$emailValidator = new Zend_Validate_EmailAddress();
$emailValidator->setMessages(
    array(
        Zend_Validate_EmailAddress::INVALID => 'Please enter in a valid email address in the format [email protected]',
        Zend_Validate_EmailAddress::INVALID_FORMAT => 'Error with format',
        Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'Error with hostname',
        Zend_Validate_EmailAddress::INVALID_LOCAL_PART => 'Error with Local Part',
        Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'Error with MX record',
        Zend_Validate_EmailAddress::INVALID_SEGMENT => 'Error with Segment'
    )
);

Try using that and see if those error messages show. Hopefully you can customise those and get the correct validation messages showing.

0
votes

@Alistair, not work your suggesion here.

// Email
  $email = new Zend_Form_Element_Text('email');

  $notempty = new Zend_Validate_NotEmpty();
  $email_validate = new Zend_Validate_EmailAddress();
  $email_validate->setMessages(
      array(
          Zend_Validate_EmailAddress::INVALID => 'Please enter in a valid email address in the format [email protected]',
          Zend_Validate_EmailAddress::INVALID_FORMAT => 'Error with format',
          Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'Error with hostname',
          Zend_Validate_EmailAddress::INVALID_LOCAL_PART => 'Error with Local Part',
          Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'Error with MX record',
          Zend_Validate_EmailAddress::INVALID_SEGMENT => 'Error with Segment'
      )
  );

  $email->addValidator($notempty , true, $email_validate)
        ->setRequired(false);
  // Submit
  $submit = new Zend_Form_Element_Submit('submit');