Registration form- #zf (finished)

so far so good, the registration form is finished, worked a little bit with #validators and #decorators, pretty cool..had some problems getting the errors and customizing the errors messages, did another intensive search on google and found the solution, it was pretty simple..
this is part of my source code:

$u_email= new Zend_Form_Element_Text(‘email’);
->setAttrib(‘size’, ‘25’)
->addValidator(‘NotEmpty’,true,array(‘messages’ => array(‘isEmpty’ => ‘custom message’)))’

as we can see one way of doing this is to pass a third parameter into addValidator,this third parameter is an array containing the new message and the property to which it will be applied.
with a simple call to getMessages() we can get the messages of the form in case a field is flag as invalid.


About phanorcoll

Fullstack Developer

Posted on January 3, 2011, in Projects, ZendFramework and tagged , , , . Bookmark the permalink. 3 Comments.

  1. This can also be written as:
    $form->addElement(‘Text’, ’email’, array(
    ‘required’ => true,
    ‘attribs’ => array(
    ‘size’ => 25
    ‘validators’ => array(
    array(‘NotEmpty’, true, array(‘messages’ => array(‘isEmpty’ => ‘…..’)))

    • Also another note, you do not always need to specify the key if you just do ‘messages’ => ‘message key’ it will also work to a certain extent.

    • thanks Mike. and you’re right that’s another way to put zf there’re many different ways to get a result..

      thanks for your comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: