2

I've got a 'booking' channel and an 'event' channel setup. Through the frontend, I need the logged in user to be able to submit a saveEntry form on the frontend which saves a new entry in the booking channel. The booking channel has two fields, both Entries fields. The first field is a relation to one user (the logged in user), and the second field is a relation to a single entry in the events channel.

When I submit the form, the entry is being created in the booking channel, both both Entries fields are blank. How do I make it save the related entries? Can't find any documentation on it.

Existing code:

<h2>Summary</h2>
<form method="post" action="" accept-charset="UTF-8" class="custom">
    <input type="hidden" name="action" value="entries/saveEntry">
    <input type="hidden" name="redirect" value="events/{{event.slug}}">
    <input type="hidden" name="sectionId" value="18">
    <input type="hidden" name="enabled" value="1">
    <input type="hidden" name="fields[userBooking]" value="{{user.username}}">
    <input type="hidden" name="fields[eventBooking]" value="{{eventID}}">
    <input type="submit" value="Confirm Booking">
</form>

Short version: How do I save a related entry through a frontend form?

4

All related fields need to be passed as an array even if it is limited to 1.

so for example change your eventBooking and userBooking hidden fields to be the following (also you may need to specify the user id when relating to a user):

<input type="hidden" name="fields[userBooking][]" value="{{user.id}}">
<input type="hidden" name="fields[eventBooking][]" value="{{eventID}}">

This should get you want you need.

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.