Zend Framework 2 - Remote form element causes validation to fail

I use a specific form in several places. In one of them, I need to ignore the form element that I installed programmatically after validation.

Because this is just an exception, I do not want to create a new form. Therefore, I thought that I would simply delete this element in the controller, for example:

$myForm->remove('myElement');

The problem is that the form will no longer be validated. I am not getting any errors, but $myForm->isValid()just returning an empty value.

Any ideas what I can do wrong?

Thank!

+5
source share
5 answers

, , ! ValidationGroup, , . :

$form->setValidationGroup('name', 'email', 'subject', 'message');
$form->setData($data);
if ($form->isValid()) {
    ...
+10

, , myElement ValidatorChain. :

$form->getInputFilter()->get( 'myElement' )->getValidatorChain()

, ValidatorChain, . post. ' Zend , , .

, " ", FormFilter. , , , Matthew - , .

@Stoyan Dimov: , BasicForm ExtendedForm. , - . .

+2

class ValidatorChain implements Countable, ValidatorInterface :

public function remove($name){
    foreach ($this->validators as $key => $element) {
        $validator = $element['instance'];
        if($validator instanceof $name){
            unset($this->validators[$key]);
            break;
        }
    }   
}

:

$form->getInputFilter()->get("xxxxx")->getValidatorChain()->remove('xxxxxx');
+1

, .

, , addValidator, :

$element- > addValidator ( ', ');

. , , , .

, , .

zf : http://framework.zend.com/manual/1.12/en/zend.form.elements.html

0

:

$form->get('product')->remove('version');

, :

$form->getInputFilter()->get('product')->get('version')->setRequired(FALSE);
0

All Articles