Prevent multiple submissions to a formit Form

Hi all.

I have a snippet which prevents someone with the same email address submitting a form more than once.
It works, but it doesn’t output anything on the screen for the users to know. It just doesn’t submit.

It’s probably very simple, but I can’t work out how to print an error to say ‘Sorory you’ve already submitted this form!’.

This is my hook below:

<?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', '', 'electionPreventDupeVotes');
    return false;
}
$modx->log(xPDO::LOG_LEVEL_ERROR, 'There are no such emails', '', 'electionPreventDupeVotes');
return true;

it’s working because the logs are updating, but how do i add a message to the user on screen?

Thanks!
Andy

Actually - I have worked it out - this always happens after I give up, post it on the commmunity, and then have another crack at it!!

For those wondering, this is how I did it - I modified the snippet above right before the ‘return false’ with this:

$voted = '<div style="background:red; color:#fff; padding:10px; border-radius:5px; ">You have already voted!</div>';

// define the placeholder and set it's value
$modx->setPlaceholder('votedPlaceholder',$voted);

and added a placeholder to the page:

[[+votedPlaceholder]]

$hook->addError('email','Email exists.');
return $hook->hasErrors();
1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.