What i wanted is not when an update occurs. That i have already made. the issue i am having is… when creating, we may enter all required fields nah… unfortunately say if a person forgets to insert his/her address… but have filled the rest which are…
Name and pro picture…
then an error will br thrown nah as address is kept to be required… now my problem is… what i get after validation errors are shown is…
the filled form with error summary where saying you must enter the address…
when i say filled form… i am saying that… it will come pre loaded the Name… and empty address (because i left it so and submitted the form) and [color="#8B0000"]finally the pro picture field which is not getting pre loaded[/color]. so user will have to fill it again and again when a validation error comes when creating the form.
why is that ? this is my problem kiran.
Hope i explained clearly this time.
let me know if there is a way to get rid from this…
Hey, still have an issue… what i wanted to be is… the file uploadin field to be loaded with old uploaded image or what ever. this helps only to play with the validation from users end still the field is going to empty.
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.
had the same problem with AJAX-validation and filefields (validation always says the field is blank) I used this approach in performAjaxValidation($model) :
//echo CActiveForm::validate($model);
echo CActiveForm::validate($model,array('news_date','order_date','header','intro','alias','body')); // validate all except "file_field"