<p>You might want to take a look at <a href="https://craftcms.stackexchange.com/questions/25901/title-field-character-length/25903#25903">this</a> </p>

<p>Your condition will be </p>

<pre><code>$author = Craft::$app-&gt;getUsers()-&gt;getIdentity();
$numberOfEntriesByUser = Entry::find()-&gt;sectionId($entry-&gt;getSection()-&gt;id)-&gt;authorId($author-&gt;id)-&gt;count();
if($numberOfEntriesByUser){
    $event-&gt;isValid = false 
} 
</code></pre>

<p>You should make sure the author is not an admin or <code>Craft::$app-&gt;getRequest()-&gt;getIsCpRequest()</code> is false otherwise you won't be able to save new entries as well. </p>

<p>Keep in mind to check for a current user as well. There won't be a user for cronjobs / other public post request </p>

CC BY-SA 4.0
2018-05-18T15:35:12.560Z
Hi Robin, Thanks once again for your help. I think the plugin sample code is just what I need - I will try it out. I appreciate you taking the time to provide that as a sample. However, the EVENT_BEFORE_SAVE event doesnt quite suit my needs because I think it would run once the user clicks Save, after having taken the time to fill in a whole listing. It would take a user some time to enter all the info, and then this would not be saved, which the user would not like.
ironfish
CC BY-SA 4.0
2018-05-18T15:35:18.723Z
I need something that would alllow me to check after a user Clicks New entry but before the user sees the fields to fill in a listing, something like EVENT ON CREATE or EVENT ON NEW ENTRY but I dont see anything like that. Please let me know if you have some ideas about that....
ironfish
CC BY-SA 4.0
2018-05-18T15:41:39.720Z
You could eventually try to use the `afterSaveElement` event to check if the user already has 3 entries and remove the permission to create new entries in this specific section. I'm not sure if you can grant the permission to edit entries without the permission to store entries. Otherwise you'll need to hide/remove the button in the CP. There is a `Craft.elementIndex` in Javascript that has an `sourceChange` event. I'll show you how to do it in 3 days since I only have my smartphone right now. You'll need to pass a variable with all sections whether the user may create a new entry or not
Robin Schambach
CC BY-SA 4.0
2018-05-18T16:55:21.537Z
Thank you Robin - that sounds like a very good option. I am fairly new to Craft and so it will take me some time to learn and work with this......
ironfish
CC BY-SA 4.0
2018-05-18T14:17:40.223Z
2018-05-18T14:17:40.223Z
Robin Schambach
<p>I have a site where users can add entries of an entry type/section called Listings. </p>

<p>I would like to limit the number of Listings to a maximum of three per user.</p>

<p>In another CMS I did this by writing a plugin that got triggered when a new Entry was created. This plugin determined the number of existing Entries for a given user and if the maximum was reached, the plugin cancelled the creation of a new entry and instead showed a message that the user had reached their maximum limit of entries.</p>

<p>Not to say that this is the best way to do it, or do it in Craft, but I am new to Craft CMS and have been looking for a hook or event that is triggered when a new entry is created, but I don't seem to be able to find anything like that.</p>

<p>I have also done a fair bit of searching on this topic and cant seem to find any Stack questions or posts on the net....</p>

<p>Any suggestions much appreciated.....</p>

<entry><limit>
How to limit number of entries to a given user/user group
# How to limit number of entries to a given user/user group

(Asked by: username_0 on 2018-05-18)

I have a site where users can add entries of an entry type/section called Listings.

I would like to limit the number of Listings to a maximum of three per user.

In another CMS I did this by writing a plugin that got triggered when a new Entry was created. This plugin determined the number of existing Entries for a given user and if the maximum was reached, the plugin cancelled the creation of a new entry and instead showed a message that the user had reached their maximum limit of entries.

Not to say that this is the best way to do it, or do it in Craft, but I am new to Craft CMS and have been looking for a hook or event that is triggered when a new entry is created, but I don't seem to be able to find anything like that.

I have also done a fair bit of searching on this topic and cant seem to find any Stack questions or posts on the net....

Any suggestions much appreciated.....

**Tags:** entry, limit

---

## 1 answers

### Answer by username_1 on 2018-05-18. Score: 1

You might want to take a look at this 
Your condition will be 
$author = Craft::$app->getUsers()->getIdentity();
$numberOfEntriesByUser = Entry::find()->sectionId($entry->getSection()->id)->authorId($author->id)->count();
if($numberOfEntriesByUser){
    $event->isValid = false 
} 

You should make sure the author is not an admin or Craft::$app->getRequest()->getIsCpRequest() is false otherwise you won't be able to save new entries as well. 
Keep in mind to check for a current user as well. There won't be a user for cronjobs / other public post request

> **Comments:**
> **username_0**: Hi Robin, Thanks once again for your help. I think the plugin sample code is just what I need - I will try it out. I appreciate you taking the time to provide that as a sample. However, the EVENT_BEFORE_SAVE event doesnt quite suit my needs because I think it would run once the user clicks Save, after having taken the time to fill in a whole listing. It would take a user some time to enter all the info, and then this would not be saved, which the user would not like.  
> **username_0**: I need something that would alllow me to check after a user Clicks New entry but before the user sees the fields to fill in a listing, something like EVENT ON CREATE or EVENT ON NEW ENTRY but I dont see anything like that. Please let me know if you have some ideas about that....  
> **username_1**: You could eventually try to use the `afterSaveElement` event to check if the user already has 3 entries and remove the permission to create new entries in this specific section. I'm not sure if you can grant the permission to edit entries without the permission to store entries. Otherwise you'll need to hide/remove the button in the CP. There is a `Craft.elementIndex` in Javascript that has an `sourceChange` event. I'll show you how to do it in 3 days since I only have my smartphone right now. You'll need to pass a variable with all sections whether the user may create a new entry or not  
> **username_0**: Thank you Robin - that sounds like a very good option. I am fairly new to Craft and so it will take me some time to learn and work with this......  

---

