I’m having trouble saving relationship data within the Channel Form. The correct related entries appear on the page, however on submitting the form, any chosen related entries are not saved. Checking the new entry in the back end shows nothing selected in the relationship field.
Can anyone advise me on what I’m doing wrong or how I can fix this?
Part of my code:
Teams that play here:
{options:sports_teams}
<input type="checkbox" name="sports_teams[]" value="{option_value}"> {option_name}
{/options:sports_teams}
I based the code above on this sample from the official documentation:
{options:my_field_name}
<input type="checkbox" name="my_field_name[]" value="{option_value}" {checked}> {option_name}</br>
{/options:my_field_name}
If I set the relationship field to required I get these error messages when submitting:
The form you submitted contained the following errors
Sports teams: This field is required.
sports_teams: This field is required.
I had no choice but to upgrade the website from EE3 to EE4 as EllisLab stopped selling EE3 licenses. Once upgraded I was able to fix this issue by using the following code (I don’t know if this works in EE3):
{custom_fields}
{if relationships}
{if allow_multiple}
{options:sports_teams}
<input type="checkbox" name="{field_name}[data][]" value="{option_value}"{checked}> {option_name}
{/options:sports_teams}
{/if}
{/if}
{/custom_fields}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.