Re: form validation wih html input FILE
| From: | John W. Holmes | Date: | Wed, 05 May 2004 14:29:40 +0000 |
| Subject: | Re: form validation wih html input FILE | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185427@lists.php.net to get a copy of this message | ||
From: "Vincent DUPONT" <Vincent.dupont@ausy.be>
> I'd like your opinion on the best way to do a form
> validation when the form contains a file upload object
> (<input type="file">)
>
> When the form does not validate, I try to re-show all values
> entered by the user.But, as far as I know, browsers do not
> allow to set the default value (local file path) of a FILE component
> I can get and display the default value in a label or text input,
> but how could I upload that file then? Will I be limited to display
> a warning message indicating that the user will have to select his/her
file again??
You're not going to be able to fill it in for them. There's no way around
that (which is a good thing).
Solutions are to either notify them to select the file again and hope they
notice, or keep the file in a temp directory when it's uploaded the first
time and call it from there when the validation is successful. Simply remove
the <input type="file"> from the form when you have the file, but make them
correct / validate the rest of the data. Then, you know that if $_FILES is
empty, you can search in the temp directory according to a hidden field /
session value you've set to look for the file. Retrieve it from there and
proceed as normal.
---John Holmes...