Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2008, 12:15 PM
Junior Member
 
Join Date: Mar 2008
Posts: 6
Default Form Validator message

Hello,

I am new in ZF and have some question :
I have a form :
Code:
public static function Login()
	{
	 	require_once 'Zend/Form.php';
	 	
	 	$LoginForm = new Zend_Form(
    	array( 
        'method'   => 'post', 
        'elements' => array( 
            'LoginName' => array('text', array( 
                'required' => true, 
                'label' => 'Prisijungimo vardas' 
            )),
            'Pass' => array('text', array( 
                'required' => true, 
                'label' => 'Slaptažodis' 
            )),  
            'submit' => array('submit', array( 
                'label' => 'Prisijungti' 
            )) 
        ), 
    ));
    return $LoginForm; 
	 	
	}
and view
Code:
$form=$this->Login();
    	
    	if ($this->getRequest()->isPost())
    	{   
    		 
    		if ($form->isValid($_POST))
    		{
    			$values = $form->getValues();   
		}
			/*else
			{
				$form->populate($_POST);	
			}*/
			
		}
    	$this->view->form = $form;
Now if textfield are empty write default message.
How can I change this message, without creating a new class who extends Zend_Validate_Abstract?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-28-2008, 12:34 PM
Junior Member
 
Join Date: Mar 2008
Posts: 12
Default Use Zend_Translate

Quote:
Originally Posted by mamyte03 View Post
Hello,
Now if textfield are empty write default message.
How can I change this message, without creating a new class who extends Zend_Validate_Abstract?
If I understand you correctly, you want to have a localized error message for your textfield?
If so, you should use Zend_Translate.
This might be of interest for you:
Akra’s DevNotes Blog Archive Simple Zend_Form Example
See comment 24-26.

To get the error codes, you can use
Code:
$this->getErrors()
in your view script.

/friedhelm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-28-2008, 03:43 PM
Junior Member
 
Join Date: Mar 2008
Posts: 6
Default

Oh.. Thanks. I saw this tutorial but not looked i comments. Thanks a lot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-28-2008, 04:22 PM
Junior Member
 
Join Date: Mar 2008
Posts: 12
Default Alternative for Zend_Translate

Quote:
Originally Posted by mamyte03 View Post
Oh.. Thanks. I saw this tutorial but not looked i comments. Thanks a lot.
As an alternative to Zend_Translate:
Code:
    $element = new Zend_Form_Element(array(
        'validators' => array(
            array('NotEmpty', false, array(
                'messages' => array('isEmpty' => 'This is a custom message')
            )),
        )
    );
Stolen from:
Nabble - Zend_Form

The i18n-section of the docs (Zend Framework: Documentation)
may help further.
/friedhelm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:42 AM.