Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davorpeic/f82844f88ca57030bf4d to your computer and use it in GitHub Desktop.
Save davorpeic/f82844f88ca57030bf4d to your computer and use it in GitHub Desktop.
Single html file upload for Assets in Grid in Channel Form - ExpressionEngine
// Warning: this requieres latest (at this moment unpublished) version of Assets 2.5.1 addon
// So, I had a need to disable File browser that Assets comes with in frontend,
// and use simple file input in a Grid fieldtype
// Official docs are ok, but not complete for use in the Grid
// http://docs.pixelandtonic.com/assets/templating/channel_form.html#using-a-file-input
// Lets say your Grid fieldtype is called 'grid_field'
// and your Assets field is 'col_id_10' (you can check what ID is in DB [check grid table for that fieldtype])
<input type="file" name="grid_field[rows][new_row_0][col_id_10]" />
// Use _filedir for local storage as mention in the official docs, I'm using S3 here
<input type="hidden" name="grid_field[rows][new_row_0][col_id_10_source]" value="1"/>
// Full example of Channel form
{exp:channel:form
channel="your_channel"
entry_id="{segment_3}" //You need to have entry_id because you are always editing eixisting entry
return="your_return_url"
limit="1"
dynamic="no"
}
<!-- Grid field hidden to mantain existing rows -->
<div class="hidden">{field:properties_docs}</div>
<!-- There will be probably more fields in the Grid, if you need to add them put them the same way (pay attention to col_id_XY) -->
<input type="text" class="form-control" id="grid_title" name="grid_field[rows][new_row_0][col_id_11]">
<!-- Assets field -->
<input type="file" name="grid_field[rows][new_row_0][col_id_10]" />
{!-- Use _filedir for local storage as mention in the official docs, I'm using S3 here --}
<input type="hidden" name="grid_field[rows][new_row_0][col_id_10_source]" value="1"/>
<button type="submit" class="btn btn-purple">Send</button>
{/exp:channel:form}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment