Yesterday, I noticed that a Javascript function stopped to work in my application. The reason was that the id of an input field used by this Javascript has changed from “ModelnameFieldname” to “Modelname”. As I didn’t change anything in my form it had to be an issue with the form helper. The “funny” thing was that the issue only occurred if the model existed (and the field didn’t exist in the model, as I learned later).

Obviously this issue was caused by a recent change in the FormHelper, and according to a comment by Nate it was intentionally: “In order to enable model association mapping for FormHelper, non-existent fields are no longer supported. In order for a field to be recognized, it must exist in the model’s schema, or have a validation rule defined in Model::$validate.”

Hm, I have to say I don’t like it as it introduces dependencies which are not obvious. So the following snippet may work in one case, but not in another case:

echo $form->create('Model');
echo $form->input('Model.field');
echo $form->end();

If the model and the field exist, then the correct code is generated. The same if the model doesn’t exist. But if the model exists, and the field not, it generates wrong code (i.e. all input fields for non-existing model fields will have the same id). So, be careful when using virtual fields.