1

I have a problem with changing messages for StringLength in Zend_Filter_Input. Code:

    $filters = array(
        'nazwa'   => 'StringTrim',
        'haslo'   => 'StringTrim'
    );           

    $validators = array(
        'nazwa'   => array(
            'allowEmpty' => false,                  
            'presence' => 'required',                       
            new Zend_Validate_StringLength(array('min' => 5, 'max' => 30)),
            array('Regex', array('pattern' => '/^[\w]+$/'))
        ),
        'haslo'   => array(
            'allowEmpty' => false,              
            'presence' => 'required',
            new Zend_Validate_StringLength(array('min' => 5, 'max' => 30))
        )
    );              

    $data = array(
        'nazwa'   => $formData['nazwa'],
        'haslo'   => $formData['haslo']
        );              

     $options = array(
            'notEmptyMessage' => "Pole '%field%' jest wymagane"
         );

    $input = new Zend_Filter_Input($filters, $validators, $data, $options);

I think I just tried everything from translating, adding options, messages in $validators and it is still default message. Please let me know how to change those default error messages (like TOO_SHORT, TOO_LONG) for new ones.

1 Answer 1

1

Try to set message for validator failure.

$validator = new Zend_Validate_StringLength();
$validator->setMessage(
  'Your cusom message about short string',
  Zend_Validate_StringLength::TOO_SHORT
);

Then add $validator to your $validators.

More information here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.