CleanTalk / craft-antispam

CraftCMS plugin `Anti-Spam protection by CleanTalk`
MIT License
1 stars 0 forks source link

Addition to docs #3

Open alanski66 opened 2 months ago

alanski66 commented 2 months ago

If you want to simply add a check on other custom forms you can add another event listener in the main file 'CraftAntispam.php' function registerEvents() Event::on( Entry::class, Element::EVENT_BEFORE_SAVE, function (Event $e) { $entry = $e->sender; $params['email'] = $entry->YOURFORMFIELD; $params['message'] = $entry->YOURFORMFIELD; if ($this->request->getIsSiteRequest()) { $result = $this->antispam->checkSpam($params); } }, );

AntonV1211 commented 2 weeks ago

Hello @alanski66! Can you tell me which custom forms will be checked by listening to EVENT_BEFORE_SAVE?

alanski66 commented 2 weeks ago

It's more that the fields above are on your form $entry->YOURFORMFIELD YOURFORMFIELD is something you want to check for spam in your form - the save event will listen to all entry saves and you are just saying if this save event contains my form field pass it to the clean talk spam check service. Hth

alanski66 commented 2 weeks ago

PS it works brilliantly

AntonV1211 commented 2 weeks ago

Thanks @alanski66! We will try to implement EVENT_BEFORE_SAVE listening in the future. Case ID: 12589