Welcome Guest, Not a member yet? Register   Sign In
Submit form with input type=file
#1

[eluser]megabyte[/eluser]
Ok

So we have a form with fields like name, addres, city (could be anything) and a file upload field for an image

When we submit the form we validate and realize the user did not enter his city. Now the file upload field is empty and the user needs to select it again.

What if anyhting has anyone come up with as a solution to this? How can we validate and keep state on the file field.


Is there a solution?
#2

[eluser]NateL[/eluser]
If you're using the form validation built in with CI, then this should help you:

RePopulating the Form
#3

[eluser]megabyte[/eluser]
you can't repopulate an input type = file though. Thats why I'm asking? Tongue
#4

[eluser]LuckyFella73[/eluser]
As far as I know it's not possible to repopulate
an input field with type=file at all for security
reasons. Otherwise you could place a form, hide
an input field (with type=file) and upload some
predefined files from the users pc...
#5

[eluser]xwero[/eluser]
You could upload the file apart from the validation. If there are error you store the data you need from the file in a temporary database and you can display some of that data under the file field.

This is just one way of dealing with uploads and keeping the form user friendly.
#6

[eluser]NateL[/eluser]
Or you could use Javascript validation which validates the fields before submitting it.

"What about people who have disabled JS?"

Well, you keep your PHP validation in as well. If they don't have JS enabled, then they will have to go back and choose the file again. With such a small percentage of people now that have their JS disabled, i seriously doubt it would cause a problem.




Theme © iAndrew 2016 - Forum software by © MyBB