<p>If I understood you correctly, you have two sections:</p>

<ul>
<li>events</li>
<li>registrations</li>
</ul>

<p>Is the user logged in? If yes, you can save the user id in your registration entry. In your events template you can check now, if a registration entry exists that is related to this event and the current user. 
See example code (untested).</p>

<pre><code>{% if currentUser %}

   {% set query = "userIdField:"~ currentUser.id %}
   {% set results = craft.entries({
      relatedTo: entry.id,
      section:'registrations'
      search: query
   }) %}

{% endif %}

{% if results|length %}
    user is already registered
{% else %}
    show registration form
{% endif%}
</code></pre>

<p>If your user is not logged in, you could (temporarily) store the registration information in a cookie (check out this plugin: <a href="https://github.com/lewisjenkins/craft-lj-cookies" rel="nofollow">https://github.com/lewisjenkins/craft-lj-cookies</a>) and do a similar check.</p>

CC BY-SA 3.0
2016-04-15T11:46:54.727Z
Yes, the user logged in and your proposal is more or less what I do already. The problem is that I still get duplicated entries from time to time.
MISC
CC BY-SA 3.0
2016-04-15T14:41:22.590Z
Perhaps the user press the registration button twice, or he use the back button. In certain circumstances this could create a second entry. To avoid the "double click" you could disable the button with javascript. Have you activated the CSRF Protection -> https://craftcms.com/support/csrf-protection? Hope this helps.
Tom Bauer
CC BY-SA 3.0
2016-04-16T08:05:30.453Z
No, CSRF protection has not been enabled yet. I will try that. Thank you very much.
MISC
CC BY-SA 3.0
2016-04-14T12:19:59.883Z
2016-04-14T12:19:59.883Z
Tom Bauer
<p>I make use of the front-end entry form for an event registration process. The event is the main entry, and every event registration an entry of a related registration section. The challenge is to see whether a user has already been registered for an event. Today, I do that with a database query before the entry form loads. But for some reason, this works not always (for example when users reload the page). How could I make the combination of two fields ("user id" and "registration status") unique? (Normally, I would do that on a database level with a unique index over the two fields.) </p>

CC BY-SA 3.0
2016-04-14T11:59:29.377Z
You could get entries for the specific section by their `authorId` and if they have one don't load the form else load the form and let them register.
mcclaskiem
CC BY-SA 3.0
2016-04-14T13:48:32.157Z
That is exactly what I do today. But nevertheless, I get duplicated entries from time to time.
MISC
CC BY-SA 3.0
2016-04-14T13:55:30.690Z
If there is only one entry from a user in a specific section you should only see one entry come back when you query based on the `authorId`, what does your template look like?
mcclaskiem
CC BY-SA 3.0
2016-04-14T17:48:33.383Z
No, there is more than one entry from a user in a section.
MISC
CC BY-SA 3.0
2016-04-15T11:52:45.710Z
I will now add a text field containing string composed of event_id and user_id and make this field value unique using the following plugin: https://github.com/joshangell/craft-unique-value
MISC
<form><field>
How to make combination of two field values unique?
# How to make combination of two field values unique?

(Asked by: username_0 on 2016-04-14)

I make use of the front-end entry form for an event registration process. The event is the main entry, and every event registration an entry of a related registration section. The challenge is to see whether a user has already been registered for an event. Today, I do that with a database query before the entry form loads. But for some reason, this works not always (for example when users reload the page). How could I make the combination of two fields ("user id" and "registration status") unique? (Normally, I would do that on a database level with a unique index over the two fields.)

**Tags:** form, field
> **Comments:**
> **username_1**: You could get entries for the specific section by their `authorId` and if they have one don't load the form else load the form and let them register.  
> **username_0**: That is exactly what I do today. But nevertheless, I get duplicated entries from time to time.  
> **username_1**: If there is only one entry from a user in a specific section you should only see one entry come back when you query based on the `authorId`, what does your template look like?  
> **username_0**: No, there is more than one entry from a user in a section.  
> **username_0**: I will now add a text field containing string composed of event_id and user_id and make this field value unique using the following plugin: https://github.com/joshangell/craft-unique-value  

---

## 1 answers

### Answer by username_2 on 2016-04-14. Score: 2

If I understood you correctly, you have two sections:

events
registrations

Is the user logged in? If yes, you can save the user id in your registration entry. In your events template you can check now, if a registration entry exists that is related to this event and the current user. 
See example code (untested).
{% if currentUser %}

   {% set query = "userIdField:"~ currentUser.id %}
   {% set results = craft.entries({
      relatedTo: entry.id,
      section:'registrations'
      search: query
   }) %}

{% endif %}

{% if results|length %}
    user is already registered
{% else %}
    show registration form
{% endif%}

If your user is not logged in, you could (temporarily) store the registration information in a cookie (check out this plugin: https://github.com/lewisjenkins/craft-lj-cookies) and do a similar check.

> **Comments:**
> **username_0**: Yes, the user logged in and your proposal is more or less what I do already. The problem is that I still get duplicated entries from time to time.  
> **username_2**: Perhaps the user press the registration button twice, or he use the back button. In certain circumstances this could create a second entry. To avoid the "double click" you could disable the button with javascript. Have you activated the CSRF Protection -> https://craftcms.com/support/csrf-protection? Hope this helps.  
> **username_0**: No, CSRF protection has not been enabled yet. I will try that. Thank you very much.  

---

