I wonder if I'm doing something wrong or if this is a bug in ZF2: When i'm trying to set some data on a form, validate it and retrieve the data it's just an empty array.
I extracted this code from some classes to simplify the problem
$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()
s show empty arrays. I don't get any Data out of the form as well as no messages. Is it my fault or ZF2's?
print_r($_POST);
andprint_r($this->getRequest()->getPost();
and provide them to narrow down your problem. – Mehalick