Safecracker file field not submitting on Safecracker form
Posted: 11 November 2010 09:23 PM   [ Ignore ]
Has a Great Personality
Rank
Total Posts:  36
Joined  2010-09-08

I’m not sure what happened, but I just upgraded from Build 20101012 to Build 20101102 of Safecracker and have run into an issue with a form that includes a safecracker file field.  There is a required field in the form, and now when you submit the form with a file in the safecracker file field, it removes the file and bring up the error page that says the field is required.  Any idea what could have changed in between those builds that would cause that?  This is working properly when you submit an entry through the Control Panel, but not when you submit through the safecracker form.

Let me know if it would help to see the form or code.

[ Edited: 11 November 2010 09:26 PM by Stephen T ]
Profile
 
 
Posted: 11 November 2010 09:34 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

We made some big under-the-hood changes since that build, so it doesn’t surprise me that there are still a few kinks to work out. I’ll do some tests and get back to you.

Profile
 
 
Posted: 11 November 2010 11:43 PM   [ Ignore ]   [ # 2 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Can I see your template code?

Profile
 
 
Posted: 12 November 2010 12:04 AM   [ Ignore ]   [ # 3 ]
Has a Great Personality
Rank
Total Posts:  36
Joined  2010-09-08

Sure - do you want to see the entire form?  I’ll start with just the ee tag and the safecracker file form field, but let me know if you want to see more:

EE Tag:

{exp:safecracker channel="channel_name" logged_out_member_id="25" status="open" dynamic_title="Form Submission - [music_title]" return="submissions/thanks"

Safecracker file upload field:

<label class="description" for="music_score">Score PDF File (under 15 MB in size) <span class="required">*</span></label>
<
input id="music_score" name="music_score" class="element file" type="file" /> 
Profile
 
 
Posted: 12 November 2010 12:12 AM   [ Ignore ]   [ # 4 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

I think this is a consequence of using the back button and the browser’s file input. I would recommend using inline error handling http://barrettnewton.com/safecracker/user_guide/entry_form/#par_error_handling
This will preserve your file field (it will actually do the upload and show a thumbnail if you encounter an error).

Take a look at this example of using inline errors: http://barrettnewton.com/forums/viewreply/6924/

Profile
 
 
Posted: 12 November 2010 12:32 AM   [ Ignore ]   [ # 5 ]
Has a Great Personality
Rank
Total Posts:  36
Joined  2010-09-08

I rolled back to the 20101012 build to get this working for now and it’s submitting fine in that build.  So why would that field not submit at all in the newest build?  Does it have something to do with the way errors are handled in the new build?

So if I just fill out the form, hit submit, and it’s stripping out the safecracker file field at that point, there isn’t a back button involved there, right?  I’m probably just misunderstanding what you’re saying and should get inline error handling working anyway, but I’m just wondering.

Thanks for the quick responses as always.

Profile
 
 
Posted: 12 November 2010 12:36 AM   [ Ignore ]   [ # 6 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

I think I’m unclear as to what exactly is happening. Maybe you could describe in more detail what’s going on? Which is the required field? Are you saying you are getting a faulty error message?

Profile
 
 
Posted: 12 November 2010 02:15 AM   [ Ignore ]   [ # 7 ]
Has a Great Personality
Rank
Total Posts:  36
Joined  2010-09-08

Sure - here’s what’s happening.

I have a safecracker form with a safecracker file field that is marked as required in the control panel. That field is called music_score.  If I fill out the form, and use the music_score field to select a file on my computer, then hit submit, it brings me to the error page saying that the music_score file field is required and doesn’t submit the form.  So, it seems that the info in the music_score field is being stripped out when I hit submit or something like that since there is information in that field, but it’s acting like there isn’t.  This ONLY happens if the field is required.  If the field is not marked as required, then the form submits and the file is uploaded just fine.  But when the safecracker file field is required, something happens where that field won’t submit any info at all.

Let me know if that doesn’t make sense.

Profile
 
 
Posted: 12 November 2010 03:33 AM   [ Ignore ]   [ # 8 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

I see what’s up. There are some hidden fields that must accompany the safecracker file field. That’s why you need to do:

<label class="description" for="music_score">Score PDF File (under 15 MB in size) <span class="required">*</span></label>
{field:music_score} 
Profile
 
 
Posted: 12 November 2010 04:05 AM   [ Ignore ]   [ # 9 ]
Has a Great Personality
Rank
Total Posts:  36
Joined  2010-09-08

Ah-ha!  That worked.  Was that a new requirement with the latest build?  Or did I just have my form build incorrectly all along and the latest build brought that to light?

Profile
 
 
Posted: 12 November 2010 04:07 AM   [ Ignore ]   [ # 10 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

The latter, we don’t officially support you creating your own file <input>. I would rather not have to include all those hidden fields, but there are limitations to what can be done with the EE fieldtype API.

Profile