It is interesting that I am doing something wrong or if it is an error in ZF2: when I try to set some data on the form, check it and extract the data, it is just an empty array.
I extracted this code from some classes to simplify the task
$form = new \Zend\Form\Form;
$form->setInputFilter(new \Zend\InputFilter\InputFilter);
$form->add(array(
'name' => 'username',
'attributes' => array(
'type' => 'text',
'label' => 'Username',
),
));
$form->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Register',
),
));
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost()->toArray());
if ($form->isValid()) {
echo '<pre>';
print_r($form->getData());
print_r($form->getMessages());
echo '</pre>';
}
}
both print_r()show empty arrays. I do not receive any data from the form, as well as messages. Is this my mistake or ZF2?
source
share