Faraona
Faraona

Reputation: 1700

Zend Form Field set Validator to invalid

How to set Form Field to invalid from controller?

Example:

$form->getElement('name')->set.... Validator to FALSE

or something similar???

Part of code:

    if(....){
    $form->getSubForm('sub_form_name')->getElement('element_name')->addError('some error message');
    }


    if($form->isValid($this->getRequest()->getPost())) {
//Form is going to be valid and execute this statment
    }

i try too with: markAsError() and hasError(); but not working :(

Upvotes: 1

Views: 3779

Answers (2)

Jose Raupp
Jose Raupp

Reputation: 11

A litle POGramation. :) Not the best way, but works fine.

            $vazio = false;
        if(is_array($nomes)){
      $vazio = true; 
              $form->addError("NomeIsArray");
        }

        if(!$vazio && $form->isValid($post)){

            }

Upvotes: 1

max4ever
max4ever

Reputation: 12142

If you use any of the addError...() or setError...() on your element it should set the validation flag to invalid, or so the documentation says

Zend_Form_Element.addError(string $message)

Add an error message and mark element as failed validation

Upvotes: 2

Related Questions