1

I have a field called "assetId" from Entry "A" with Field Type "Entries" and Source "B". How can I build a form so that a relation between these two entries will be established.

In the craft backend I can add a new entry in Entry "A" and can use the Button "Add an entry" to select the suitable Entry from "B". This works fine. A record is written in the Table craft_relations.

How can I build a user form in the frontend to get this. I tried following form with a hidden field "fields[assetId]" which is set to the id of the suitable content:

<form method="post" accept-charset="UTF-8" enctype="multipart/form-data" class="send-form" id="send-form">
    <input type="hidden" name="action" value="entries/saveEntry"/>
    <input type="hidden" name="sectionId" value="34">
    <input type="hidden" name="enabled" value="1">
    <input type="hidden" name="fields[assetId]" value="1478" id="hidden-assetID">
    [... some more fields ...]
     <input class="btn-vote" type="submit" value="send">

</form>

The entry is saved correctly, but without the assetId. There is no relation between targetId 1478 and the new entry in the Table craft_relations established. What am I doing wrong?

2

After research with lots of trail & error I found the solution. I just had to add [] to my hidden field to establish the relation:

<input type="hidden" name="fields[assetId][]" value="1478" id="hidden-assetID">

The leading hint was here: Setting User field type from a front end form

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.