Skip to Main Content

Channel Form with Relationship and Playa Fields

Today I created a channel form to allow visitors to upload testimonials to a site. The site already has a couple hundred testimonials added which meant that I needed to use the existing fields which include a native relationship field and a playa relationship field. Both of those fields are set up to be multi-select in the backend, however on the front end we want a single select.

Today I created a channel form to allow visitors to upload testimonials to a site. The site already has a couple hundred testimonials added which meant that I needed to use the existing fields which include a native relationship field and a playa relationship field. Both of those fields are set up to be multi-select in the backend, however on the front end we want a single select.

This meant that using {field:field_name} wouldn't work as it will output the field to look exactly as it does in the control panel. Fortunately it's not difficult to get this up and running. First the native relationship field. Note that the name field format.

    
    
      <select name="field_name[data][]" id="field_name" class="form-control">
    <option value="">--Choose One--</option>

    {options:field_name}
        <option value="{option_value}" >{option_name}</option>
    {/options:field_name}
</select>
    
  

For the playa field an embed is needed in order to wrap the options in a channel entry tag. In your main template embed like this:

    
    
      {embed="includes/_entry_select"}
    
  

Finally your embed code is here again Note that the name field format:

    
    
      <select name="field_name[selections][]" id="field_name" class="form-control">
    <option value="">--Choose One--</option>

    {exp:channel:entries channel="channel_short_name" dynamic="no"}
        <option value="{entry_id}" >&#123;title&#125;</option>
    {/exp:channel:entries}
</select>
    
  

Now on the front end form the the relationship/playa fields are single selects and easily styled to match the look of your site rather than the control panel styles. The main reason I pursued this is to have a single select on the front end without changing the multi select option in the backend and affecting legacy content.