0
votes

How can i get rid of Zend default error not to show "Value is required and can't be empty"

Thanks

I'm using this method:

$this->addElement(
    'text',
    'testname',
     array(
        'label' => 'User Name',
        'required' => true,
        'filters' => array(
          'StringTrim'
        )
    )
);
2
You should pass a valid value to whatever method/function throws that error !Poelinca Dorin
it could be done by using $element->setRequired(false);tawfekov

2 Answers

4
votes

If you need to change the actual message text then use something like this:

$field = new Zend_Form_Element_Text('field');
$field ->setRequired(TRUE)
    ->addValidator(
        'NotEmpty', //validator name
        FALSE, //do not break on failure
        array(messages' => array(
                'isEmpty' => 'INSERT CUSTOM MESSAGE HERE' 
            )
        )
    )

Here you change the 'isEmpty' message of the NotEmpty validator.

Or if you defined the element differently.

$element = $this->getElement('text');
$element->addValidator('NotEmpty', //validator name
    FALSE, //do not break on failure
    array(messages' => array(
            'isEmpty' => 'INSERT CUSTOM MESSAGE HERE' 
        )
    )
 )
2
votes

In Zend_Form this is the default error message of the default validator 'Empty'. To remove this validator, on the element add the removeValidator() function with 'empty' as the parameter:

$element->removeValidator('Empty');

This is assuming you have made a form in Zend_Form, that you have POSTed an empty value and are trying to validate it?

Going forward, please provide more information.