3

I have relationships field Foo where people can have more than one entry, basically a multiple relationships field.

I am not using {field:foo} to output my form field. Instead I am using multiple checkboxes to save the multiple relationships.

What is the proper way to do this?

Is there a native way to do this or do I have to resort to implementing a function in extensions to work them out?

1 Answer 1

3

To output the information this worked for me:

<p class="grid-row"><em>Fav Style:</em><span>{options:member_favourite_drinks}{if selected}{option_name},{/if}{/options:member_favourite_drinks}</span></p>

... and to have this in a select list:

{custom_fields}
     {if field_name=="member_favourite_drinks"}
            <select id="{field_name}" name="{field_name}[data][]" multiple="multiple">
                  <option value="">Select...</option>
                  {options}
                      <option value="{option_value}"{selected}>{option_name}</option>
                  {/options}
             </select>
     {/if}
{/custom_fields}

... checkboxes will need an embed inside the form:

{embed="_embeds/.drinks-list"}

contents would be:

{exp:channel:entries channel="drinks" order="title" sort="asc" dynamic="no"}
    <div class="form-item form-item-checkbox form-item-small">
            <label for="member_favourite_drinks_{count}">
                    <input type="checkbox" name="member_favourite_drinks[data][]" value="{entry_id}" id="member_favourite_drinks_{count}">
        <span>{title}</span>
    </label>
</div>{/exp:channel:entries}
4
  • Thank you for your response. This snippet, name="member_favourite_drinks[data][]", was what I was looking for. Commented Oct 7, 2013 at 3:01
  • Nice solution, how are the checkboxes checked? (when editing)
    – GDmac
    Commented Oct 7, 2013 at 4:30
  • @GDmac I had to make a custom plugin for it. The channel entries solution has no way of knowing which values are selected by itself. Commented Oct 7, 2013 at 6:16
  • You could pass the entry_id to the embed, and try using the parents tag with the embed:entry_id. If it is a match, just output checked or checked="checked".
    – GDmac
    Commented Oct 7, 2013 at 7:09

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.