0

Iam new to Zend Framework please help me out...

// create text input for pharmacy name
  $name = new Zend_Form_Element_Text('name');
  $name->setOptions(array('size' => '30'))
    ->setRequired(true)
    ->addValidator('NotEmpty')
    ->addValidator('Alpha');
  $name->getValidator('NotEmpty')->setMessage('Please enter pharmacy name.');
        $name->getValidator('Alpha')->setMessage('PharmacyName can only contain letters and spaces.');


  // create submit button
  $submit = new Zend_Form_Element_Submit('submit');
  $submit->removeDecorator('HtmlTag');
  $submit->setLabel('Save')
  ->setOptions(array('class' => 'submit'));

  // attach elements to form
  $this->addElement($cd)
   ->addElement($name)
   ->addElement($submit);
3
  • 1
    and whats your question? - please post controller code Commented Nov 12, 2010 at 8:43
  • I have edited your post to be more readable, but it is still not very clear what your actual question is. You added a code sample without any description of the actual section that is causing you trouble. If you want an answer to this question, please be more descriptive. Commented Nov 12, 2010 at 8:46
  • Hi, I have the same problem: error message from validator doesn't appear. This is only when (german) umlauts are within the message, otherwise it works fine. Any ideas? Commented Mar 27, 2012 at 20:57

1 Answer 1

1

I use a construct as the following to define element parameters:

$this->addElement('text', 'o_title', array(
        'label'      => 'title....',
        'required'   => true,
        'filters'    => array('StringTrim','WordLength'),
        'validators' => array(
            array('validator' => 'StringLength', 'options' => array(0, 40,'utf8',   
                                  'messages'=>array('stringLengthTooLong'=>'Text too long'))),
                   array('NotEmpty', true,  
                             array('messages'=>array('isEmpty'=>"Field must not be empty")))
            ),
        'maxlength' => 40,
        'decorators' => array('Uniform'),
        'description'=> 'input only 40 chars'
    ));

Validators are specified in two ways in the above code .... Each validator can have many messages ...

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.