<p>Correct way is little bit longer.</p>

<p>Firstly, you need your own plugin, you can generate skeleton here: <a href="https://pluginfactory.io/" rel="nofollow noreferrer">https://pluginfactory.io/</a> It's better than rewrite someone else's, because you can't update it after you add a code.</p>

<p>Secondly, you add your beforeSend Event to Plugin class by add it to init function - the function will be generated in step one - it is in the YourNamePlugin php file in root.</p>

<p>If you start a new project, it is better to work in Craft 3.</p>

CC BY-SA 4.0
2018-10-15T21:44:02.540Z
2018-10-15T21:44:02.540Z
lenka
<p>Very new to Craft, so can someone please tell me what class/file I'd add the 'The beforeSend event' code, as I'd like to filter out some spam?</p>

<p>The documentation <a href="https://docs.craftcms.com/v2/plugins/hooks-and-events.html#hooks" rel="nofollow noreferrer">https://docs.craftcms.com/v2/plugins/hooks-and-events.html#hooks</a> says that the new event listener should be added to the plugins 'init' function, but there isn't one.</p>

<p>many thanks</p>

CC BY-SA 4.0
2018-10-15T14:07:24.730Z
Which version of Craft do you use? 2 or 3. Do you look to any another plugin and copy function structure?
lenka
CC BY-SA 4.0
2018-10-15T20:54:13.987Z
The version is 2.6.3017, I don't know where to put the call to the event code or where the event code should go, I could hack it but I would like to know the correct way?
user8844
<plugin-contactform>
P&T Contact Form v1 adding code for 'beforeSend'
# P&T Contact Form v1 adding code for 'beforeSend'

(Asked by: username_0 on 2018-10-13)

Very new to Craft, so can someone please tell me what class/file I'd add the 'The beforeSend event' code, as I'd like to filter out some spam?

The documentation <https://docs.craftcms.com/v2/plugins/hooks-and-events.html#hooks> says that the new event listener should be added to the plugins 'init' function, but there isn't one.

many thanks

**Tags:** plugin-contactform
> **Comments:**
> **username_1**: Which version of Craft do you use? 2 or 3. Do you look to any another plugin and copy function structure?  
> **username_0**: The version is 2.6.3017, I don't know where to put the call to the event code or where the event code should go, I could hack it but I would like to know the correct way?  

---

## 1 answers

### Answer by username_1 on 2018-10-15. Score: 1 | Accepted answer

Correct way is little bit longer.

Firstly, you need your own plugin, you can generate skeleton here: <https://pluginfactory.io/> It's better than rewrite someone else's, because you can't update it after you add a code.

Secondly, you add your beforeSend Event to Plugin class by add it to init function - the function will be generated in step one - it is in the YourNamePlugin php file in root.

If you start a new project, it is better to work in Craft 3.


---

