activeFileField should not create a second hidden input

It seems that the CHtml method activeFileField creates a file input for uploading a file, but it also creates a second identical but hidden file input with it.

Having looked at the comment about this in the source code, it would seem that this is to preserve the Controller’s ability to recognise that a model is being updated rather than consulted, in the case where a model contains only one user-updatable attribute which is a filefield (I presume in this case that the resulting form would only generate a [ModelName] entry in the $_FILES array and not the $_POST array, thus meaning that the test in the controller if (isset($_POST[ModelName])) would conclude that we were not trying to update the model, although I haven’t checked this out).

While I appreciate that this kind of scenario may cause a problem, I think that this solution is fudged, and not appropriate.

One of the drawbacks, for example, is that if you are using a validator on your filefield (in order to accept only .jpg files for example), if the validation fails, then your resulting update form will contain two identical errors for your one filefield (and I can’t see any easy way around this).

I can’t think of any perfect solution to this, but perhaps we could make the id of the submit button default to the model name for CActiveForm instances, since the test isset($_POST[ModelName]) would still work then, and the time people most want to change the id of the submit button is for GET requests when they don’t want it polluting the Url. I appreciate that this has its drawbacks too, but I think this is preferable to making a fudge solution.

If necessary, I don’t think it is unreasonable that the developer should be required to make specific modifications to cope with this (presumably rare, as in perhaps once per application) specific situation, rather than introducing an unnecessary input element.

Please let me know if you have any thoughts, otherwise I will submit this as a bug.