yii-user file field validation when other field doesn't validate

Right now, I have a registration form with two required fields: "name" and "photo" (where photo is a "File Field" widget field)

If I leave “name” blank but browse for a photo from my hard drive and click submit I will get an error (as expected) that the “name” field is empty. No problem, I’d like to type the name and submit again as the photo has already uploaded.

However, if I fill in the name field and submit, I’ll get an error that the photo is blank. The form doesn’t remember that the photo was uploaded in the last step.

Is there some way for the form to remember the already uploaded image?


I’ve tried adding a hidden field to the registration form that contains the value of the already uploaded photo filename if one was uploaded in the previous step. I’m just unsure how to override the default widget validation so it ignores the fact that the validation doesn’t need to be done since it’s already uploaded. Instead, on second submission, it assumes the file upload field is blank (which it is), ignores the hidden field, and then redirects the user back to the registration form again.

Any idea how to have two different validation methods depending on whether it is being uploaded through the file widget or if it was uploaded previously?


Custom hidden field for storing file name (or ID, depends on your architecture) + custom validator for file field that should check if file or hidden fields are not empty.