error messages in form

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

error messages in form

aoohralex
I must create my own 3. error communicates for field - 'name' - in Symfony Framework it would be:
$this->setValidators(array(
          'name' => new sfValidatorString(array('min_length' => 2, 'max_length' => 50, 'trim' => true),
          array('required' => 'Name is required.', 'min_length' => 'Name is too short.', 'max_length' => 'Name is too long.'))
    ));

In Zend Framework I have:
$this->addElement('text', 'name', array(
            'label'      => 'Name:',
            'required'   => true,
            'filters'    => array('StripTags', 'StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(2, 50)),
            )
        ));

How can I add these 3. error communicates to that field above ??

Error communicates:
- Name is required.
- Name is too short.
- Name is too long.
Reply | Threaded
Open this post in threaded view
|

Re: error messages in form

Joó Ádám
If I understand you correctly, you want to add custom error messages:
http://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.validators.errors

$name = new Zend_Form_Element_Text('name', array(
    'label' => 'Név',
    'maxlength' => 50,
    'required' => true,
    'validators' => array(
        array('NotEmpty', true, array('messages' => array('isEmpty' =>
'Meg kell adnod a program nevét.'))),
    ),
));
Reply | Threaded
Open this post in threaded view
|

Re: error messages in form

padraicb
In reply to this post by aoohralex
May I suggest you read the documentation before asking questions on the mailing list? I don't mean to be rude, but the documentation has all your answers and it supports a search form also. Failing that, run a google search using "site:http://framework.zend.com/manual/en" as a search term.
 
Pádraic Brady

http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative



From: aoohralex <[hidden email]>
To: [hidden email]
Sent: Saturday, September 19, 2009 7:27:57 PM
Subject: [fw-general] error messages in form


I must create my own 3. error communicates for field - 'name' - in Symfony
Framework it would be:
$this->setValidators(array(
      'name' => new sfValidatorString(array('min_length' => 2, 'max_length' =>
50, 'trim' => true),
      array('required' => 'Name is required.', 'min_length' => 'Name is too
short.', 'max_length' => 'Name is too long.'))
    ));

In Zend Framework I have:
$this->addElement('text', 'name', array(
            'label'      => 'Name:',
            'required'  => true,
            'filters'    => array('StripTags', 'StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(2,
50)),
            )
        ));

How can I add these 3. error communicates to that field above ??
Error communicates:
- Name is required.
- Name is too short.
- Name is too long.

--
View this message in context: http://www.nabble.com/error-messages-in-form-tp25524216p25524216.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: error messages in form

aoohralex
Joo thx for help. Thx Joo and thx this website (I have found it today): http://www.oplabo.com/article/12

I have created:
array( 'NotEmpty', true, array(
                    'messages' => array(
                       'isEmpty' => 'Name is required.'
                 ))),
array( 'StringLength', true, array(
                    'min' => 0,
                    'max' => 50,
                    'messages' => array(
                       'stringLengthTooLong' => 'Name is too long. Max %max%.',
                        'stringLengthTooShort' => 'Name is too short. Min %min%.'
                 ))),


Padraic you always say about documentation - but in documentation wasn't everything what is on this site: http://www.oplabo.com/article/12 .
For example in documentation: http://framework.zend.com/manual/en/zend.validate.messages.html I don't see Error Message Key which I needed.