cakephp/cakephp — pull request #563 by stefanozoffoli (2012-03-15 08:57:11+00:00)
Title: Change the way a field is retrieved for fixing multiple field bug.

I found a problem when using FormHelper to create input fields with multiple values.

Here's an example:

```php
request->data['Contact']['others']); $i <= $n; $i++): ?>
Form->input('Contact.others.' . $i . '.0', array(
'label'	=> __('Key'),
'type'	=> 'text',
));
?>
Form->input('Contact.others.' . $i . '.1', array(
'label'	=> __('Value'),
'type'	=> 'text',
));
?>

```

Without this patch, cakephp put "required" class in all "Contact.others.n.0" divs, even if I didn't create a "validate" rule for that key.

In fact, when FormHelper->input() calls Helper->field() method to determine the name of the field, that method doesn't strip all the numbers of a multiple field key.
In this case, for all the "Contact.others.n.0" Helper->field() returns "0", and FormHelper->_introspectModel() returns true because of this:

```php
if ($key === 'validates') {
if (empty($field)) {
return $this->fieldset[$model]['validates'];
} else {
return isset($this->fieldset[$model]['validates'][$field]) ?
$this->fieldset[$model]['validates'] : null;
}
}
```

All the inputs get the "required" class because of the empty() returns true.

I think that also any possible validation rule for the "others" field are not considered without this patch, but I'm not really sure.