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?

1 Answer 1

8

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.

1
  • Thank you SO much :)
    – iamkeir
    Nov 7, 2019 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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