Issues

ZF2-340: NotEmpty being added to Not Requred InputFilter

Description

Creating an InputFilter using InputFilterFactory (shown below) and setting required=FALSE still results in the addition of the Zend\Validator\NotEmpty Validator being called and triggered when submitting the form (and therefore the NotEmpty error is shown)

 
//Creating the input filter
$factory = new InputFactory(); 
$inputFilters->add( $factory->createInput(array(
                'name'     => 'new_password',
                'required' => false,
        'allowEmpty' => true,
                
            )));

//Checking the form in the controller
$form->setData($request->post());       
if ($form->isValid()) { 
....
}

outputting the object shows 'required' and 'allowEmpty' are set correctly. In addition, the validation Chain is NULL. The NotEmpty validator should not be applied.


object(Zend\InputFilter\Input)#268 (9) {
  ["allowEmpty":protected]=>
  bool(false)
  ["breakOnFailure":protected]=>
  bool(false)
  ["errorMessage":protected]=>
  NULL
  ["filterChain":protected]=>
  NULL
  ["name":protected]=>
  string(12) "my_element"
  ["notEmptyValidator":protected]=>
  bool(false)
  ["required":protected]=>
  bool(false)
  ["validatorChain":protected]=>
  NULL
  ["value":protected]=>
  NULL
}

Zend Version '2.0.0beta4'

Comments

Update: AllowEmpty is not being set. A workaround is to set AllowEmpty after the factory has created the Input


$inputFilters->add( $factory->createInput(array(
                'name'     => 'new_password',
                'required' => false,
        'allowEmpty' => true,
                
            ))->setAllowEmpty(true));

allowEmpty is invalid; it is actually allow_empty the required part does not set allow empty and i suppose it should be explicit to force a not empty validator.

This is fixed in the following PR: https://github.com/zendframework/zf2/pull/1467