0

I am using the latest version of Freeform and trying to populate a multi-select with a relationship field of entries. Here is the code, at the moment it is only outputting the first result and not looping properly. Has anyone tried this before and can therefore advise?

{related_documents_for_request}
            <select id="{selected_documents:title}" name="{selected_documents:title}" multiple="multiple"> 
                  {options}
                      <option value="{related_documents_for_request:selected_documents:title}"{selected}>{related_documents_for_request:selected_documents:title}</option>
                  {/options}
             </select>
{/related_documents_for_request}

1 Answer 1

0

Let's assume you have a Freeform custom field called my_multi_select_field. Let's also assume the fieldtype is a textarea, since it can contain multiple values, which in turn are saved as newline-separated data if the data comes in as an array (as would happen with a multi-select field).

Let's assume you're using the native EE relationship field, and that it's called related_documents_for_request. In that case, try this code:

<select name="my_multi_select_field" multiple="multiple"> 
   {related_documents_for_request}
   <option value="{related_documents_for_request:title}">{related_documents_for_request:title}</option>
   {/related_documents_for_request}
</select>

If your relationship field comes from a native EE Grid field which in turn contains a native EE Relationship column, then the above code would have to be tweaked, but the main point is that the opening and closing <select> element tags should be outside of the looping part of the code, and that the <select> element's name="" should be the name of your Freeform custom field.

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.