Copy link to clipboard
Copied
Hello, all,
I'm in the middle of troubleshooting an issue with server-side form validation, and am now curious.
If a form contains <input type="file" name="foo" /> but no file is selected when the form is submit, does the form element "foo" exist? I mean, I know that if no checkboxes are checked, that element doesn't exist on form submit. Do file inputs do the same?
V/r,
^ _ ^
I believe the form field will be there but the value will be empty.
Yes the form field for "foo" will be there but an empty string.
Copy link to clipboard
Copied
I believe the form field will be there but the value will be empty.
Copy link to clipboard
Copied
Yes the form field for "foo" will be there but an empty string.
Copy link to clipboard
Copied
Thank you, BeRadB and John. I kind of suspected, but wasn't sure, and a Google search didn't help.
V/r,
^ _ ^
Copy link to clipboard
Copied
Hi WolfShade,
The following point is perhaps just a bit of craziness, but I shall put it out there. The file-upload form, together with content-type, is:
<form enctype="multipart/form-data">
<input type="file" name="foo" />
</form>
That is, the content-type is binary. Which gets me thinking that, when you submit the form without selecting a file, the form field exists, and has value null (clients then interpret the null as "").
This just might be relevant to a server whose validation code or response-header expects binary input.