ZF-7793: An element with the same name as its subform handles the input value incorrect

Issue Type: Bug Created: 2009-09-07T12:36:57.000+0000 Last Updated: 2010-03-31T09:47:44.000+0000 Status: Closed Fix version(s): Reporter: Roel van Duijnhoven (roelvd) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: - ZF-9348



Take a look at the following code. It appears that elements that have the same name as the subform that is containing them, don't handle the input value correctly. In fact, the input value always seems to get truncated to the first char of the input string.

<pre class="highlight">
$form = new Zend_Form();

// Create a subform
$subform = new Zend_Form_SubForm();

// Add an element  with a validator to that subform
$font = new Zend_Form_Element_Text('font');
$font->addValidator( new Zend_Validate_StringLength(3));

// Now add the subform to the central form and give it the same name as the previous element
$form->addSubForm( $subform, 'font' );

// Provide some valid input
$form->isValid( array(
    'font' => array(
        'font' => 'a valid input string' ) ) );

// Output equals stringLengthTooShort
echo current($subform->font->getErrors());

// Output equals: t
// in fact, all input will be truncated to a lenght of 1 char
echo $subform->font->getValue();



Posted by Tim Brayshaw (twisty) on 2009-11-20T03:45:34.000+0000

Here's more code to confirm...

<pre class="highlight">
$subFormName = 'test';

$testElementNames = array(
    'pass' => 'anything',
    'fail' => $subFormName,

foreach ($testElementNames as $elementName) {
    $form = new Zend_Form;
    $subForm = new Zend_Form_SubForm;
    $subForm->addElement('text', $elementName);
    $subForm->addElement('text', 'otherField');
    $form->addSubForm($subForm, $subFormName);
        $subFormName => array(
            $elementName => 'Test content.',
            'otherField' => 'More test content.',


<pre class="highlight">
  'test' => 
      'anything' => string 'Test content.' (length=13)
      'otherField' => string 'More test content.' (length=18)

  'test' => 
      'test' => string 'T' (length=1)
      'otherField' => string 'T' (length=1)

Note that the values for all elements in the subform are truncated to the value of the first letter of the rouge element.

It seems that the values returned are only mangled after calling "isValid" on the form. (For instance changing "isValid" in the code above to "setDefaults" results in the correct return values from "getValues".

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

Fixed in [ZF-9348]

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

Reopened because suggested fix is not reviewed and committed yet.

Posted by Christian Albrecht (alab) on 2010-03-31T09:47:44.000+0000

Matthew Weier O'Phinney resolved [ZF-9348] Patch applied to trunk and 1.10 release branch.

Have you found an issue?

See the Overview section for more details.


© 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.