Keeping the correctly filled in data when validating an html form with php
Hi, I don't know if this is an html or php issue but here goes:
I'm making a php/html form in which users can upload small files.
When validating the form if the users hasn't correctly filled in part of the form, the php returns them to the form with the incorrect areas highlighted while keeping the correct content.
Standard stuff, but my problem is that when this happens the file upload box (input type=file) always loses its content so that the user has to browse for the file again.
Does anyone know if there is a way to keep the file address like you can do with every other input type (by using value etc)?
Thanks in advance.
sol90 posted this at 10:01 — 12th October 2006.
He has: 7 posts
Joined: Aug 2006
Two things:
1.
RFC was written in 1995. I can't find a more updated version. Which means either current browsers don't like to handle it, or there is a more recent version that I don't know about.
2.
Despite what the RFC says, I could not get PHP to "keep" the value inside the file input box. A possible workaround, depending on your requirements, is to keep the variable in sessions and output the filename above/below/beside the input box.
If someone knows a better way :light: , by all means please share! Thanks
Greg K posted this at 12:03 — 12th October 2006.
He has: 2,145 posts
Joined: Nov 2003
The question here is if the browser actually sends the file "location" to the server. I imagine that for security reasons, it will not, but i could be wrong.
-Greg
sol90 posted this at 00:54 — 13th October 2006.
He has: 7 posts
Joined: Aug 2006
Good point, Greg. I believe the RFC mentions security as an issue as well.
mawooshen, I'm sure you probably know this already but here goes...
I did a bit of testing on XAMPP and it appears that the $_FILES array does not have the full path name of the file (it has the file name and a temporary file path). In addition, the RFC talks about the 'value' in (input type=file) only tells the browser of a default file name. Like I said in my previous reply, I wasn't able to get that working. I'm on windows, using php5, apache from xampp. You can try your luck on other setup environments, I suppose.
Anyone else have any input, I'm kind of curious to find a better way to do this.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.