Issues

ZF-8022: Form isValid() when using elements that are using belongsTo()

Issue Type: Sub-task Created: 2009-10-06T06:57:07.000+0000 Last Updated: 2010-04-16T06:16:05.000+0000 Status: Resolved Fix version(s): Reporter: Jim Hill (wiseguydigital) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

Related issues: - ZF-9348

Attachments:

Description

I'm pretty sure that this is a bug, but I may be mistaken.

This issue occurs when building forms with many subforms. Within one of these subforms is at least one element using belongsTo(). The problem is that when the form is submitted and isValid() is applied to the form, the value of the 'arrayed' elements defaults to null even if a value was entered pre-submission.

I have had a look around and I believe that this may be something to do with the problem, but please forgive me as I'm not a great developer. It seems to be that when validating, it can't find the key for the $data array, due to it being nested. In my own code I have modified the isValid() function and now my forms are working as expected, so I hope this helps.

I have modified (around line 2004 of Zend/Form.php):

    foreach ($this->getElements() as $key => $element) {
        $element->setTranslator($translator);
        if (!isset($data[$key])) {
            $valid = $element->isValid(null, $data) && $valid;
        } else {
            $valid = $element->isValid($data[$key], $data) && $valid;
        }
    }

My modification is as follows:

        if (null != $element->getBelongsTo()) {
            $parent_array = $data[$element->getBelongsTo()];
            $key = $parent_array[$key];
            $valid = $element->isValid($key, $data) && $valid;
        } else {

            if (!isset($data[$key])) {
                $valid = $element->isValid(null, $data) && $valid;
            } else {
              $valid = $element->isValid($data[$key], $data) && $valid;
            }
        }

Comments

Posted by Jim Hill (wiseguydigital) on 2010-01-20T08:30:34.000+0000

Still having the same issues.

Posted by Christian Albrecht (alab) on 2010-03-18T08:23:13.000+0000

Partially Fixed in [ZF-9348]

Posted by Christian Albrecht (alab) on 2010-03-25T13:24:01.000+0000

Will work on belongsTo after finishing elementsBelongTo.

Posted by Christian Albrecht (alab) on 2010-04-16T06:16:04.000+0000

Duplicates now parent ZF-9607 which has a Patch and Unit Test attached.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts