I just can't get my first ZF2 form to work! Here is the abbreviated controller action to demonstrate my workflow:
$viewData['form'] = $form = new InstituteEditForm();
$form->setInputFilter(new InstituteInputFilter());
$defaultValues = ...;
$form->populateValues($defaultValues);
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
print_r('VALID<br/>');
var_dump($form->getData());
} else {
print_r('INVALID<br/>');
var_dump($form->getMessages());
var_dump($form->getData());
}
}
return new ViewModel($viewData);
The InstituteInputFilter defines Inputs with Filters and Validators for some elements, but not for all. The problem is, that in case the form validates fine, form->getData() returns all values, not just those that have an Input attached, i.e. it returns unvalidated data. This should not be the case, should it?
Thank you so much!
the normal step to setup a form is the following below. i comment the code so you should have no problem to understand what method is used for. your main error is that you don't
bind
the default values to the form class.