Welcome Guest, Not a member yet? Register   Sign In
retain multi file upload if validation is not successful

How can I retain multi file upload if validation is not successful

<input name="file1" type="file" />
<input name="file2" type="file" />

I'm not sure but i don't think you can do any validation with the form validation class on a file field you will get the errors through the upload function and you will get them in an array.

You can return the array from your upload function or put it in a var and use it in a flash session to be display when redirected.

if user chose file1 is correct, and file 2 is not correct, form validation is fail. And I don't want user must chose file1 (correct)again. User must only choose file2 again. It's mean that Smile

Ok well there is no support in the validation class for this type of validation.

You can probably do a call back to execute your own validation but that is where you need to get creative since the post var FILE is an array that contains not only the information of the file being uploaded but also the error and success messages of the upload operation and other pieces of info.

Not an easy answer.

So there is no easy way to do this specially if you have other fields being submitted in the same form like a regular text field.

The reason is that when you validate a regular field you can use the validation class and if there is an error it will just return the errors and with some code you repopulate the fields with the submitted values.

Now in order to get any kind of errors in file upload the file needs to go through the process uploading so if you have two files and one fails you can't repopulate the successful field since the file has already been uploaded and if you do then you will re upload the file again and this can either overwrite the file or create a new one and you will end up having duplicates of the files.

So depending on your form I would have a separate upload form this way you can have more control over the uploads.

So I hope I made my self a little clear and in the long run maybe you'll find a way to do it by writing a very large code block but at the end you will see that making things simple an efficient are the way to go.

So here is a link to the php file upload section so you can understand a little more the mechanics behind it.


Theme © iAndrew 2016 - Forum software by © MyBB