Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Element removed, InputFilter still validates removed Element #126

Open
koseduhemak opened this issue Oct 21, 2016 · 2 comments
Open

Element removed, InputFilter still validates removed Element #126

koseduhemak opened this issue Oct 21, 2016 · 2 comments

Comments

@koseduhemak
Copy link

If one uses init() Method to add elements within a Fieldset, they are not completely removable. While the element isn't present in the form anymore, the respective InputFilter (which addresses validation of the previously removed element) still is.
This leads to an invalid form, but no error messages are shown (because the elements which cause the error do not exist and are therefore they are not rendered nor the error messages are).

Wouldn't it be more suitable if an element is removed to remove their InputFilter(Specification) too?
I think we need to modify the isValid-Method in "zend-form/src/Form.php" to skip InputFilters of previously removed elements.
I know we are able to set elements which should be validated via setValidationGroup. If a form has many fieldsets / elements this method is somewhat hackish. Is there any other possible solution to this problem?

My code:

$this->form->get('user')->get('address')->remove('street');
$this->form->get('user')->get('address')->remove('number');
$this->form->get('user')->get('address')->remove('postcode');
$this->form->get('user')->get('address')->remove('city');
$this->form->get('user')->get('address')->remove('additionalField');
$this->form->get('user')->get('address')->remove('phone');
$this->form->get('user')->get('address')->remove('country');

VAR_DUMP if form is invalid (normally we have error messages here):

if ($this->form->isValid()) {
    $this->redirect()->toRoute('successRoute');
} else {
    var_dump($this->form->getMessages());
}

VAR_DUMP is executed but getMessages delivers empty array.

Any clues?

@kynx
Copy link

kynx commented May 11, 2017

It sounds to me like you're removing the elements after you've set the data (or called bind() or prepare()). I'm pretty sure the default input filter isn't created until that point. Can you remove them earlier?

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at laminas/laminas-form#21.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants