5

I see for users, I can add a hidden field <input type="hidden" name="deleteUserPhoto" value="1" /> to remove the uploaded photo, however I need to allow this functionality for an assets field in an entry form.

I have tried submitting an empty file field, but it just retains the existing uploaded asset after submission.

Is there a trigger similar to deleteUserPhoto that I can use here?

6

File fields are used for uploading new images. To delete all the Assets for a field, submit a hidden field with no values.

<input type="hidden" name="fields[assetsField]" value="" />

If, on the other hand, you want to retain some of them, then make that hidden field an array with the values you'd like to keep. Like this

<input type="hidden" name="fields[assetsField][]" value="someAssetId" />
<input type="hidden" name="fields[assetsField][]" value="someOtherAssetId" />

someAssetId and someOtherAssetId being the Asset IDs you'd like to keep for that field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.