Issues

ZF2-340: NotEmpty being added to Not Requred InputFilter

Issue Type: Bug Created: 2012-06-05T06:56:55.000+0000 Last Updated: 2012-06-08T15:45:52.000+0000 Status: Resolved Fix version(s): Reporter: Jaime Ruiz (jgruiz75) Assignee: Mike Willbanks (digitalstruct) Tags: - Zend\InputFilter

  • Zend\Validate\NotEmpty

Related issues: Attachments:

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)

<pre class="highlight"> 
//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.

<pre class="highlight">
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

Posted by Jaime Ruiz (jgruiz75) on 2012-06-05T07:16:38.000+0000

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

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

Posted by Mike Willbanks (digitalstruct) on 2012-06-08T15:25:35.000+0000

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.

Posted by Mike Willbanks (digitalstruct) on 2012-06-08T15:45:52.000+0000

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts