Answer the question
In order to leave comments, you need to log in
How to set allow_empty on a form element using a factory in ZF2?
There is an element that has by default (allow_empty == true):
namespace Application\Form\Element\Text;
use Zend\Form\Element\Text;
use Zend\InputFilter\InputProviderInterface;
use Zend\Validator\NotEmpty;
class Login extends Text implements InputProviderInterface
{
public function getInputSpecification()
{
return array(
'name' => 'login',
'required' => true,
'allow_empty' => true,
'validators' => array(
array(
'name' => 'notEmpty',
),
),
);
}
}
$form = $factory->createForm(array(
'elements' => array(
array(
'spec' => array(
'type' => 'Application\Form\Element\Text\Login',
),
),
),
'input_filter' => array(
array(
'name' => 'login',
'allow_empty' => false,
),
),
));
$form = $factory->createForm(array(
'elements' => array(
array(
'spec' => array(
'type' => 'Application\Form\Element\Text\Login',
'allow_empty' => false,
),
),
),
));
Answer the question
In order to leave comments, you need to log in
The form element does not have the allow_empty property, it is the Input property (which is stored in the image and likeness of the form in the InputFilter), and is used there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question