uploaded file is gone after validation


my problem is simple, i have a form with several text fields + file, some of them required (file is optional).

User is filling the form, choosing his avatar and clicking 'send', than my validation rule says that "username" field has too few characters, no problem so far, form rerenders with error messages and… file is gone. user has to upload it one more time ON EVERY VALIDATION (that returns error).

it looks like a design flaw or i'am missing something? i mean there should be some mechanism to persist data about uploaded file during validation stages (could be many of them), some hidden form fields?

i can hack some solution into  CHtml::activeFileField but would like to know if there is a better approach?

no one has this problem before?

I guess this is a normal behaviour see docs


"Note, this is a temporary file which will be automatically deleted by PHP after the current request is processed."

means if page is rendered with the error the file will be deleted afterwards.

So you have to create a backup on error and use this again.

Or you create a separate form only for uploading an image, which is a better solution.

Regards Horizons