ZF-7793: An element with the same name as its subform handles the input value incorrect
Description
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.
<?php
$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));
$subform->addElement($font);
// 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();
?>
Comments
Posted by Tim Brayshaw (twisty) on 2009-11-20T03:45:34.000+0000
Here's more code to confirm...
Output:
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.