Welcome Guest, Not a member yet? Register   Sign In
Best practices for file upload validation and form validation
#1

[eluser]megabyte[/eluser]
I have always wondered what would piss off a client the least when it comes to forms.

Let's say you have an admin are with a form that has 10 fields, 5 required fields and a file upload.

Now the client some how misses 1 of the required fields, so the form validation returns an error and now the file has to be selected once again.

This isn't too much of a big deal if the file is required, however if the file is not required and an error is returned because they missed a required field, then they won't get an error when they resubmit the form and forget to choose a file.

Then they don't realize they didn't reselect the new file, and start sending nasty emails saying there is an issue with the admin area and some files were not updated correctly.

Now I haven't had anyone complain yet, but I'd like to know I remove as much frustration as possible.

What is a person to do?

I tried placing the file upload inside a callback function, and this worked. This way the file is uploaded no matter what. Problem is I am having troubles figuring out how to store this temp image name. I tried using a hidden field, but the question is, how do you pass the value back to the form, and populate the hidden field before the form is validated?


Any ideas or solutions welcome.
#2

[eluser]JoostV[/eluser]
You could store the temp name and original name in a session.

Show the original name in the form next to the upload field to show the user that the file was uploaded succesfully, even though validation failed.
#3

[eluser]mikelangelo11[/eluser]
Well ordinarily the processing script,used this way,separate from the page with the html form,shouldn't have a doctype unless it outputs content and even then I'd not worry about that.That would be just for errors.I'd tell the user to hit backspace to get back to the form and correct what's wrong and resubmit. Once there are no more errors,it would move to next phase which is the actual posting of the message to the file and the return to whatever page was next in the chain confirmation or whatever.I remember dealing once with this script, back when Sharron was doing something on a Godaddy account, and we had quite an adventure figuring out just what the stupid thing was meant to do and how, as it was so unlike any email action script we'd dealt with before.
#4

[eluser]adamp1[/eluser]
What I do in this situation is as follows:

1) The user fills out the form and submits and image.
2) The image is verified and uploaded to a temp area available to the web. We add details of the uploaded image to a session flashdata variable.
3) The form is validated and fails so we pass the user back to the form.
4) We check the flashdata variable, if it is set we display a little preview of the uploaded image. The user can re-submit the form without having to re-upload the image.

If you then tie this method in with an ajax image upload script its very nice functionality.




Theme © iAndrew 2016 - Forum software by © MyBB