3

I have a custom Element Type to which I can add several custom fields. I can create a front end form with most of those custom fields and the submitted data saves just fine. However, I'm getting some odd behavior with the Assets field.

I can save Assets fields from the front end of Craft to Craft sections just fine. And I can edit one of the Entries for my custom Element types on the backend and upload an Asset just fine there as well.

But when I submit an Asset from the front-end for a new Entry with this custom Element type, I don't get the right behavior.

What does happen (as far as I can tell):

  1. The asset uploads and appears in the target upload folder
  2. A new row in the craft_relations table is created correctly identifying the asset and the element that it is related to.

What doesn't happen:

  1. The uploaded asset doesn't appear in the Asset index. Even if I reindex assets for this particular folder, it never shows up in the Assets file manager.
  2. When I visit the individual entry page in the CP, the Asset never appears. (But if I upload the asset directly from this CP page, the asset then does appear on this same page)

I'm struggling to know where to look to troubleshoot this. What would cause an Asset not to display properly when it's uploaded from the front end but to work fine when it's uploaded from the back end? Could I be missing some data on the front end submission? My form uses enctype="multipart/form-data" and the asset field is as simple as it gets (and I've tried several variations (<input type="file" name="fields[uploadfield]" >)

2
  • First thing I'd do is throw xDebug against it. Set a breakpoint on EntriesController->saveEntry() and step through it line-by-line to see what's going on.
    – Brad Bell
    Commented Aug 10, 2014 at 16:00
  • I'm having this problem also, Hopefully the Craft team can jump in with some insight.
    – etx
    Commented Jan 26, 2015 at 21:47

1 Answer 1

1

I looked into this extensively and the one thing I found is that if your element type uses a custom content table, the save procedure will be done properly but when Craft needs to display the asset in the index, inside an asset selection modal, or an asset field, it simply won't look in the right place and unless you copy your asset's locale and title to the Craft content table from your custom content table, it won't show up.

I've made @Brad aware of this but they haven't fix it yet, at least not in the last release that I can tell.

Your Answer

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

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