1

I have a channel form with a relationship field options: loop. I'm trying to also get a custom field from this relationship. Is that possible? If yes, how?

{exp:channel:form channel="message_on_hold"}
  {options:moh_voice_female}

     <input type="radio" name="moh_voice_female[data][]" id="moh_voice_female" value="{option_value}"{checked}> {option_name}

     ### Relationship Field : Custom Field ###

     {moh_voice_female}{moh_voice_female:voice_talent_sample}{/moh_voice_female}
     {relationhip_field}{relationship_field:custom_field}{/relationhip_field}

     ### This would work with exp:channel:entries ###

  {/options:moh_voice_female}
{/exp:channel:form}

# moh_voice_female is a relationship field
# voice_talent_sample is a custom field
1

You don't actually say if your trying to edit the field on the child entry or just display it?

If I assume your trying to just view it, try something like this :

{exp:channel:form channel="message_on_hold"}
  {options:moh_voice_female}
    <input type="radio" name="moh_voice_female[data][]" id="moh_voice_female" value="{option_value}"{checked}> {option_name}

    {!-- Display Data from related child entry --}
    {exp:channel:entries entry_id="{option_value}" dynamic="no"}
      {title}
      {voice_talent_sample}
    {/exp:channel:entries} 

  {/options:moh_voice_female}
{/exp:channel:form}

What we're doing here is starting a standard channel:entries, feeding the entry_id (value) from the relationship field and displaying some info.

Of course, you need to watch out for parse order (inward ect) but you should be able to sus that out. You may be tempted to try and incert a second channel:form inside the first to gain editing of the child, however this won't work as you'll end up with 2 forms, one inside the other (form inception, see this answer).

Otherwsie, if your trying to edit it :

What you're trying to achieve is not possible, just like in the admin section when you edit an entry with a playa on it you're only editing the parent entry, you can change the playa value but this is not pointing to the child entry, it's referencing the child entry.

while channel:entries will parse the child (as it knows what you set for the relationship value) when on the channel form for the parent entry you can only affect the entry being pointed to by the parent, you can't iterate into the desired child entry, after all who knows what child you might pick while editing the parent?

What you may be able to do is make a 2 step form, where :

  1. Present a Channel Entry form for the parent, allow user to select child or create new

  2. After the Parent is set, present a second entry form for the chosen child (or create a new entry for the child if it doesn't exist)

2
  • Awesome, thanks! I only tried to display the child entry. I had to add limit="1" to exp:channel:entries to make it work as expected. Now I only need to figure out why options:moh_voice_female won't accept offset="4". – Franz May 21 '15 at 6:41
  • That probably warrents a new question Franz, as it doesn't really relate tot he subject of this issue, but do post it and I'm sure one of us can help (I'd have to dig through the docs myself on the option tag parameters). – Blatant May 21 '15 at 8:43
0

It is weird I tried the solution of @Blatant (that seems very wel, except I had to put name_of_the_relashionship_field:name_of_the_custom_field to have it outpouting something) but it only gives me the relashionship information for the last one of the options (and the empty value one).

{exp:channel:form channel="mychannelname" return="test/index" error_handling="inline"}
<label for="facture_de_reference">Facture de référence</label>
        <div>{instructions:facture_de_reference}</div>
        <div class="error">{error:facture_de_reference}</div>
        <select name="facture_de_reference[data][]">
        {options:facture_de_reference}
            <option value="{option_value}"{selected}>{option_name}
            {!-- Display Data from related child entry --}
            {exp:channel:entries entry_id='{option_value}' dynamic='no' status="open|closed|brouillon|checke|envoye"}
                {facture_de_reference:payement_recu}
            {/exp:channel:entries}
            </option>
        {/options:facture_de_reference}
        </select>
{/exp:channel:form}

it output :

<div id="facture_de_reference">
    <label for="facture_de_reference">Facture de référence</label>
    <div></div>
    <div class="error"></div>
    <select name="facture_de_reference[data][]">
       <option value="">-- non</option>
       <option value="5">F-2016-001</option>    
       <option value="6">F-2016-002</option> 
       <option value="7">F-2016-003 non</option> 
    </select>
</div>

And what it shoud have gave me :

<div id="facture_de_reference">
    <label for="facture_de_reference">Facture de référence</label>
    <div></div>
    <div class="error"></div>
    <select name="facture_de_reference[data][]">
       <option value="">-- non</option>
       <option value="5">F-2016-001 non</option>    
       <option value="6">F-2016-002 oui</option> 
       <option value="7">F-2016-003 non</option> 
    </select>
</div>

How to make it work correcty and have the content of "payement_recu" custom field for every facture_de_reference's option as showed just above?

EE version : 3.3.2

1
  • 1
    Hi pikarge, please post this as a new question rather than an answer. You will have much better chance of getting help that way. – Alex Kendrick Jun 8 '16 at 12:57

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.