Formit - prevent duplicate submissions based on email address

Hi again!!
This is all great - but I’ve hit a slight snag.
If I create more than one ‘quiz’ on a site, the snippet prevents the owner of the email address from playing ALL quizzes (Not just the one that they have played).

Is it possible to use the ID of the form to limit submissions JUST to that form?

Or does this make it a lot more complicated?

Thanks
Andy

In Formit, each form has a Name which is automatically generated by Formit using the ID of the last page that was submitted before it’s saved to the database (e.g. form-240 - 240 is the resource ID of the page which submitted the data).

Hi Andy,
test this please:

[[!Formit?
 ...
 &hooks=`yourCustomSnippet,email`
 &formName=`form-[[*id]]`
 ...
 ]]
<?php
$modx->addPackage('formit', $modx->getOption('core_path').'components/formit/model/');

$email = $hook->getValue('email'); //play with this email, put here emails that occur for the first time or those that are already in the database
$formName = $modx->getOption('formName', $scriptProperties, '');

if($modx->getCollection('FormItForm',array('values:LIKE' => "%$email%", 'form' => $formName))){
    $modx->log(xPDO::LOG_LEVEL_ERROR, 'Email exists', '', 'yourCustomHook');
    return false;
}
$modx->log(xPDO::LOG_LEVEL_ERROR, 'There are no such emails', '', 'yourCustomHook');
return true;

You. Are. A. Total. Legend!!!
It works - just like that - thank you so much. :smile:

I have learnt a lot from this - I love the MODX community!!

Andy

Thanks :wink: And you’re welcome!
P.S. finally you may remove debug info:

$modx->log(...);

And error.log will be much clearer)

Yes I removed the debugging info thanks.

Thank again!
Andy

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.