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?

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}
| improve this answer | |
  • Thank you for your response. This snippet, name="member_favourite_drinks[data][]", was what I was looking for. – developarvin Oct 7 '13 at 3:01
  • Nice solution, how are the checkboxes checked? (when editing) – GDmac Oct 7 '13 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. – developarvin Oct 7 '13 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 Oct 7 '13 at 7:09

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.