I have a file field in the form
i set it as a required field
The submit the form with a file selected
—> Error required field file is empty.
if i make the file field not required it works perfectly???
Bug or am i doing something stupido???
Thanks, N
Hi nevsie,
You cannot make the file upload field a required field with Freeform. It’s a pseudo field and not actually an existant field in Freeform, nor can it ever be. That’s why you’re experiencing the behaviour you describe. ![]()
Your only other option would be to find or come up with a Javascript solution to make it required.
I’d like to know more about this. Can you explain the pseudo field you describe and why it can’t be required? It seems like a limitation, namely when clients complain their users aren’t attaching *something* that should have accompanied the form. Unfortunately giving them the “it’s a pseudo field, that’s why” answer likely won’t fly. ![]()
Thanks!
Limber,
I’m not sure what else you want me to say. I personally agree, being able to require that field would be great. However, when the required=”” parameter was added into Freeform, it was only coded to check on ACTUAL fields you have in the Fields tab of the Freeform CP. Perhaps the file field was overlooked, or perhaps to get that validated was A LOT more work. I don’t know. ![]()
Anyway, it is on the Feature Requests list and it’s possible we’ll revisit this in the future.
Thanks Kelsey. Definitely a bummer for an otherwise terrific tool.
limber, use a javascript validation solution and this isn’t a problem. Not only that but you can perform validation without having to leave the page. I’m using Freeform on three forms on http://monderer.com/contact and jquery tools validation. It works great as I get to process forms using Freeform, easily the best solution on the planet for processing forms online, and my validation gets to happen inline. Click submit without filling out any fields to see what I mean.
A simple way to use javascript to require a file field
Your HTML should look like this
{exp:freeform:form file_upload ="Uploads" required="file"}
File:
<input type="file" id="photoupload" name="file1" value="" class="text" />
<input id="hiddenfile" type="hidden" name="file" value="" />
<input type="submit" name="submit" value="Upload" />
{/exp:freeform:form}
Your JS should look like this (assuming jQuery)
$("#photoupload").change(function(){
$('#hiddenfile').val(this.value);
});