File fields are different then classic text fields... it's because a file field does not only have the filename in the field... but a file to be uploaded to... you can think of them as they are connected... so you cannot pre-populate a file field with the file name.
To explain the workflow:
- a user enters some non-valid data for any other field, chooses the file to be uploaded and submits the form
- at the submit time the HTTP protocol sends the form data togetherwith the chosen file to the server
- at that time in your action you can access the file with $_FILE that resides in some temporary server folder
- now... if the validation fails you (we) are displaying (rendering) again the input form, in other words we are sending to the client browser a new form to be shown with the validation errors
- so as the users gets this new form even if you could pre-populate the previous chosen file name... you cannot in any way pre-populate the file content to be uploaded
There are few solutions that I can think of
- use ajax/client validation so to be sure that when the form is submited, all the fields will pass the validation.
- make the picture upload separate (that is the reason why most software like forums have the avatar/profile picture upload in a separate form)
There is some more advanced solutions but they resemble the above second method... like having the whole form with the file upload together and then when the file is selected to upload that file with ajax even before the form is submited... but that is the most complicated and has some more thinking about it as the user can decide to not submit the form but the picture is already uploaded.
Posted From : File Field
I Solved using javascript append the file of that record and hide when selects new file. hence as per now not found perfect solution. Hers the code
To Display Files
<?php
if($model->register_id != Null || $model->register_id != "")
{
$attribute=CHtml::encode($model->medical_documents);
$file = str_getcsv($attribute ,",");
?> <div id="UploadedFiles"> Uploaded Files: <?php
foreach($file as $i=> $record)
{ ?>
<div>
<span title="File Path :<?php echo Yii::app()->baseURL . "/Documents/" . $file[$i]; ?>">
<?php echo $file[$i];?>
</span>
</div>
<?php } }?>