I have the following code on my channel form to allow for a single file attachment:
<input class="d-block" type="file" name="vault_files" id="attachment">
<input type="hidden" name="vault_files_hidden_file">
<input type="hidden" name="vault_files_hidden_dir" value="12">
How can I allow more than one file to be uploaded?
vw000, do you want to do this with manually creating the fields vs the custom field loop? The code below works if you’re just using the custom field loop:
{custom_fields}
{if file}
<div class="sm:col-span-4 mb-8">
<label class="block text-sm font-bold text-gray-700 ">
{field_label}
<span class="text-xs font-light">{field_instructions}</span>
</label>
<div class="mt-1 border-gray-300 rounded-md border border-solid p-2">
{display_field}
</div>
</div>
{/if}
{/custom_fields}
And here’s code that worked for me when I had 2 file fields.
<input type="file" name="test_file_1" />
<input type="hidden" name="test_file_1_directory" value="5" />
<input type="hidden" name="test_file_1_hidden_file" value="{test_file_1}{file_name}{/test_file_1}" />
<input type="file" name="test_file_2" />
<input type="hidden" name="test_file_2_directory" value="5" />
<input type="hidden" name="test_file_2_hidden_file" value="{test_file_2}{file_name}{/test_file_2}" />
Thank you, Andy. Not sure what you mean with manually creating the fields or custom field. I just created the File field in the EE control panel and then hard coded the field name into the HTML as per my example above.
In your 2 fields example, I see you have test_file_2 and test_file_2_directory.
Does this mean I have to create a second File field for the second file? And a third Field field for a third file in the control panel? The reason I ask is because the value is the same.
In my quick test, I tried to use the same File field and same upload directory and just tried to add a second HTML upload code to the form.
ohhhh.. are you wanting to create a bulk upload field? being able to submit multiple files in one field? If so, the file field by default doesn’t support this. So you would need to be using a field that does support bulk uploading or create your own field that does this. Otherwise, yes, you would need to have multiple file fields and multiple inputs (one for each field).
Re: Manually creating the fields. You can see in my first example I’m using tags like {display_field}
inside the {custom_fields}
tag pair. Using this method, EE will automatically output everything necessary for that field (inputs, folder selection dropdown, etc). The other method, I manually created the inputs for the file. This is a longer way to do it, but provides a lot more fine control.
That is ok, if it’s not supported. I only need 5 files on the form to be uploaded. I don’t mind creating the fields as long as all go to the same upload folder. Ideally a Drag & Drop files like you have here on this forum would be better. Maybe there is a plugin for that?
I will test this out. Thank you.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.