Validation on file upload
Posted: 19 June 2008 10:54 AM   [ Ignore ]
Newbie
Rank
Total Posts:  9
Joined  2007-06-04

Maybe I am missing something but I can’t find anything in the documentation that explains how to make file fields required for submission. Is this possible?

I tried

required="name|email|file1"

but no luck. Thanks for any help and also for Freeform!

Profile
 
 
Posted: 19 June 2008 11:27 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3373
Joined  2006-10-18

That’s how you do it smile

Are those the Names of the form fields?

 Signature 
Profile
 
 
Posted: 19 June 2008 12:10 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  9
Joined  2007-06-04

Thanks, that’s what I thought LOL

Here’s my form

{exp:freeform:form form_name="jobs" required="name|email|file1" notify="myemail@email.com" return="jobs/success" file_upload="Job Applications" template="job_application" send_attachment="yes" send_user_email="yes" send_user_attachment="no" user_email_template="job_receipt"}
<p>Name<br />
<
input type="text" name="name" value="" />
</
p>

<
p>Email<br />
<
input type="text" name="email" value="" />
</
p>

<
input type="file" name="file1" />
<
input type="submit" name="submit" value="submit" />

{/exp:freeform:form}

When I submit it validates ok but I get

Notice: Undefined index: file1 in /..snip../modules/freeform/mod.freeform.php on line 670
The form you submitted contained the following errors

* The following field is required: Name
* The following field is required: Email
* The following field is required:

It looks like it has no label, but I’m not sure where to set this for the file upload. I running the latest builds of both EE and Freeform.

Thanks again for your help.

Profile
 
 
Posted: 19 June 2008 12:38 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3373
Joined  2006-10-18

That error message is happening because it’s looking for a field named “file1” as a custom field in the Freeform CP. If it does not exist, it will return that error. In this case, you’re trying to make the file upload for attachements a required field. smile

You might be able to work around this by creating a custom field in the Freefrom CP called “form1” and it might runs it’s course.
Or, you might not be able to specify the file attachment field as a required field…

 Signature 
Profile
 
 
Posted: 19 June 2008 01:21 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  9
Joined  2007-06-04

Almost..

Adding the field file1 with a label to the freeform field list does fix the PHP notice and the label is shown correctly in the unordered list. But if you correctly submit a document with all required fields validation fails as it is looking for a text field rather than a document.

I’ll have to hope the client doesn’t notice for now wink

Profile
 
 
Posted: 19 June 2008 01:23 PM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3373
Joined  2006-10-18

I figured that might happen…

You could alternatively try Javascript validation smile

 Signature 
Profile
 
 
Posted: 19 June 2008 01:27 PM   [ Ignore ]   [ # 6 ]
Newbie
Rank
Total Posts:  9
Joined  2007-06-04

Thanks for clearing it up for me..

jQuery to the rescue…

Profile