I have a booking form on my site, which when submitted creates a new entry which has two fields: an Entries field which links to a single User, and another Entries field which links to a single Event.
The title field of the entry is set automatically to "[date of event] - [username]".
The problem is that some users are booking twice for the same event. We need a way to limit bookings to ONE PER USER. Is there a way to prevent an entry with the same title being created, and rather than just failing to submit the form, give the user an error message saying "you can't book more than one place"?
Form:
<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/book/complete/{{eventID}}">
<input type="hidden" name="sectionId" value="18">
<input type="hidden" name="enabled" value="1">
<input type="hidden" name="fields[userBooking][]" value="{{userID}}">
<input type="hidden" name="fields[eventBooking][]" value="{{eventID}}">
<input type="submit" value="Confirm Booking" class="button secondary">
</form>
Related question (possibly could be solved with the same answer) - I need to limit the number of bookings an event can take in total. So for example:
- Event One: Bookings per user: 1, Total places: 35
- Event Two: Bookings per user: 1, Total places: 50
This needs to be done with template code, not a plugin. Any ideas?