I cannot get the sfFillInForm filter to work with radio buttons in the current beta.
I have a form
<?php echo form_tag('product/order') ?>
<?php echo radiobutton_tag('test[]', 'value1') ?> VALUE1
<?php echo radiobutton_tag('test[]', 'value2') ?> VALUE2
<?php echo input_tag('textfield') ?>
</form>
in the validation file for this action I wrote
fillin:
enabled: on
When validation fails the form is repopulated (text input) but not the radio buttons.
I tracked down the problem to sfFillInForm.class.php:
if ($type == 'checkbox' || $type == 'radio')
{
// checkbox and radio
$element->removeAttribute('checked');
if ($this->hasValue($values, $name) && ($this->getValue($values, $name) == $value || !$element->hasAttribute('value')))
{
$element->setAttribute('checked', 'checked');
}
}
There is a condition $this->getValue($values, $name) == $name. In case of the radio button $this->getValue() returns an array which is of course never equal to the value of the current radio button.
The getValue() method
protected function getValue($values, $name)
{
if (array_key_exists($name, $values))
{
return $values[$name];
}
return sfToolkit::getArrayValueForPath($values, $name);
}
will result in the execution of the second return statement, which returns an array.
I'm not sure about the overall purpose of sfToolkit::getArrayValueForPath(), so I currently don't know how to fix.