Here goes…
This is for the entry form. I can do an Edit form too if there’s big demand.
Install Extension.
Set up your file upload locations/preferences as required.
Create a new custom field, field type: File, and set your upload location.
Get the field_id number for your custom field.
Build your SAEF as normal.
Paste in something like:
<label for="content">File Upload:</label>
<input class="required" id="file_content" title="Please upload a file. This field is required." name="field_id_9_img[]" type="file" class='file' />
<input type="hidden" value="" class="file" name="field_id_9"/>
<input type="hidden" value="file" class="file" name="field_ft_9"/>
Replace the ‘9’ in my code above with the field_id number from step 4.
Test
Thanks for starting this thread, wondermonkey. I feel like I’m getting close. My little front-end file upload SAEF is doing everything but uploading the file. I was a little curious about the second line you posted here (112 is my field_id):
<input type="hidden" value="" class="file" name="field_id_112"/>
<input type="hidden" value="file" class="file" name="field_ft_112"/>
Is that really supposed to be “ft” on the second line? These fields look almost identical but one has a value of ‘file’ and the other has an empty value - and, of course one has ‘id’ and one has ‘ft’.
Also, is the ID on the input field supposed to match the short name of the field, or doesn’t that matter? I’m going to go back into the main thread to see if I’ve missed anything.
OK, I got this working with only a few extra things to do in addition to what you posted. Building on and updating your instructions:
Install Mark Huot’s File Extension.
Set up your file upload locations/preferences as required.
Create a new custom field, field type: File, and set your upload location.
Get the field_id number for your custom field. (in my example here, 112)
Build your SAEF as normal.
Paste in something like (at the most minimal):
<input type="hidden" name="field_id_112" value="" />
<input name="field_id_112_img[]" type="file" class="file" />
We need the SAEF to have an enctype of “multipart/form-data”, which it does not by default. So download and install Jermaine M’s SAEF Enctype Extension from this post in the original “File” thread.
Modify SAEF Enctype extension for your needs. It wouldn’t work out of the box for me because my SAEF has a dynamic and always different “URI” so I changed the options to look for the weblog id of the weblog where I’m storing files. This is the line you’ll need to modify in one way or another (appx line 96):
ORIGINAL CODE(looking at the URI hidden field)
if (isset($options['hidden_fields']['URI']) && $options['hidden_fields']['URI']=='/post/images/')
$options['enctype']='multi';
MY MOD (changing which hidden field to look at)
if (isset($options['hidden_fields']['weblog_id']) && $options['hidden_fields']['weblog_id']=='19')
$options['enctype']='multi';
Test
Jump for joy and think about how we may not have to do any of this stuff when 2.0 comes out.
Thanks to wondermonkey for starting this thread - which is certainly easier to search and read than the original thread.
Hey Masuga, Can I just say that your #7 & 8 are really confusing, but you did remind me of a key mod that I did to get this to work. My apologies for not posting it.
This would be step 7.5 (between 7 and 8):
In mod.weblog_standalone.php, find the following lines around 1444:
$data = array(
'hidden_fields' => $hidden_fields,
'action' => $RET,
'id' => 'entryform'
);
and insert this line (plus a comma after the last field)
'enctype' => 'multipart/form-data'
it will therefore be:
$data = array(
'hidden_fields' => $hidden_fields,
'action' => $RET,
'id' => 'entryform',
'enctype' => 'multipart/form-data'
);
Is that really supposed to be “ft” on the second line? These fields look almost identical but one has a value of ‘file’ and the other has an empty value - and, of course one has ‘id’ and one has ‘ft’.
Yes, if you look at the DB, you’ll see a field for field_ft_xx which stores the format of the field.
Also, is the ID on the input field supposed to match the short name of the field, or doesn’t that matter? I’m going to go back into the main thread to see if I’ve missed anything.
No, I do that so it makes sense to people reading it and to manipulate it with javascript (good practice).
Actually the extension isn’t bad at all. If you have the same return parameter every time, you just change one small thing. For me, my SAEF is embedded on a single-entry page - and I have many entries, so the return is different every time. However, in my case, I’m only uploading to weblog_19 from a SAEF, so I told the extension to look for that hidden parameter.
Is it working from the Control Panel? If not then you should head back to the original thread to start troubleshooting. That sounds like a problem with the ability to upload files, not with the SAEF. Also ensure that your SAEF works without uploading any files first.
That sounds like it’s beyond a problem with the File extension and SAEF, or if not then it’s very likely you’re missing something basic. What version of EE are you using? I haven’t tested any of this on EE1.6.3 yet, only 1.6.2.
Keep playing with it though. When you take out the file upload form entirely from your SAEF does it work? Are your inputs named appropriately (very important)?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.