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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:21:32+00:00 2026-06-15T10:21:32+00:00

I’ve used validator errors customization example from this answer: https://stackoverflow.com/a/4881030/822947 , but I need

  • 0

I’ve used validator errors customization example from this answer: https://stackoverflow.com/a/4881030/822947, but I need to override some of translated errors with addValidator() or setMessage()/setMessages(). Examples below doesn’t work (seems, built in translator has priority?)… How can I do it?

$field->addValidator ('Alpha', false, array ('messages' => array (Zend_Validate_Alpha::NOT_ALPHA => 'My msg')));

$Alpha = new Zend_Validate_Alpha ();
$Alpha->setDisableTranslator (true);
$Alpha->setMessage ('My msg', Zend_Validate_Alpha::NOT_ALPHA);

$Alpha->setMessages (array (Zend_Validate_Alpha::NOT_ALPHA  => 'My msg'));
$field->addValidator ($Alpha);

UPDATE
The problem not in the way I add validator and set messages to it.

My goal is to localize all error messages. But for some form fields I need to add more specific messages.

For example, in my lang/translate.php I have common
Zend_Validate_Alpha::NOT_ALPHA => 'Value contains non alphabetic characters',

but for name field I need more specific
Zend_Validate_Alpha::NOT_ALPHA => 'Field can contain only alphabetic characters and spaces',

The problem is specific message ignored when I enable built in translator. So for example code

$form = new Zend_Form ();

$validator = new Zend_Validate_Alpha ();
$validator->setMessages (array (
    Zend_Validate_Alpha::NOT_ALPHA => 'xxx %value% x'
));

$form->addElement ('text', 'digit', array (
    'validators' => array (
        $validator
    )
));

$name = new Zend_Form_Element_Text ('name');
$name->addValidator ('Alpha', true, array (
    'allowWhiteSpace' => true,
    'messages' => array
    (
        Zend_Validate_Alpha::NOT_ALPHA => 'my more specific localized msg',
    )
));

$form->addElement ($name);

$form->isValid (array (
    'digit' => '___',
    'name' => '___',
));

Zend_Debug::dump ($form->getMessages ());

when translator disabled, I have

array(2) {
  'digit' =>
  array(1) {
    'notAlpha' =>
    string(9) "xxx ___ x"
  }
  'name' =>
  array(1) {
    'notAlpha' =>
    string(30) "my more specific localized msg"
  }
}

when translator enabled, I have messages from lang/translate.php

array(2) {
  'digit' =>
  array(1) {
    'notAlpha' =>
    string(104) "common localized msg"
  }
  'name' =>
  array(1) {
    'notAlpha' =>
    string(104) "common localized msg"
  }
}
  • 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-06-15T10:21:32+00:00Added an answer on June 15, 2026 at 10:21 am

    The problem is that Alpha validator does not support options array in parameters to constructor. You have to set them separatelly.

        $form = new Zend_Form ();
    
        $validator = new Zend_Validate_Alpha ();
    
        /* Custom error message */
        $validator->setMessages (array (
            Zend_Validate_Alpha::NOT_ALPHA => 'xxx %value% x'
        ));
    
        $form->addElement ('text', 'digit', array (
            'validators' => array (
                $validator
            )
        ));
    
    
        $form->isValid (array (
            'digit' => '___'
        ));
    
        Zend_Debug::dump ($form->getMessages ());
    

    Update

    The problem is with your translator then.

    I have my translator configured like this:

    resources.translate.adapter = Array
    resources.translate.data = APPLICATION_PATH "/test-translate"
    

    file en.php:

    return array (
                    "notAlpha" => 'my Translated alpha'
    );
    

    and it works.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.