Quote from: Raavi at Apr 20, 2007, 12:19 PM
Great snippet. very very useful. I actually got it to work
One issue... resubmitting the form i.e. if I refresh the page... re-enters the data in the database. Whereas eForm shows a message like this "This form was already submitted succesfully. There is no need to submit your information multiple times."
How can we curb multiple/duplicate entries in to the database of the same form data.
Are you by chance using &gotoid= parameter? I think if you use gotoid to point to a different page, that refreshing the ending page does not resubmit POST data. This may be one way to prevent your issue.
Another possible solution is to use a plugin/snippet to create a unique SESSION_ID for the current user. If you can insert this SESSION_ID in your table during INSERT/UPDATE, write the logic to first check that the currently defined SESSION_ID does not exist in the table prior to INSERT, etc.
If you can’t alter your db table, you could always set some sort of BOOLEAN/FLAG on successful insert and store in PHP’s
$_SESSION
scope.
If eForm is throwing the message the form was already submitted, but db insert is still occuring, try using an alternate eForm custom function handler other than eFormOnBeforeMailSent, such as eFormOnMailSent (Thanks, TobyL!)
NOTE: I have updated the primary example to use this function.
I have done this before using and a custom preventDupes function:
&eFormOnBeforeFormMerge=`preventDupes`
function preventDupes()
{
global $modx;
// Confirm if dupe
$checkDupe_sql = $modx->dbQuery(’
select
count(*) as count
from
your_database.your_table
where
session_id = "’.$_SESSION[unique_id_defined_earlier].’"
’);
// NOTE: The above section could be modified to check for a flag stored in $_SESSION, rather than in the db table...
// Check that dupes don’t exist for provided temp_id
if( array_shift( $modx->fetchRow( $checkDupe_sql) ) > 0 )
{
// Set placeholders
$chunkArr = array(
’dupe_entry’ => ’It appears you have already completed this action. Duplicate entries are not allowed. Thank you.’
);
// Output the dupe alert
echo $modx->parseChunk( ’dupe_entry_tpl’, $chunkArr, ’[+’, ’+]’ );
// Prevent form load
return false;
}
return true;
}
This is where
dupe_entry_tpl is a Chunk containing a Duplicate Entry Error placeholder
[+dupe_entry+] and any other markup for styling of the message, etc.
Just a possible way to help with dupe inserts...I’m not sure it’s the fault of either eform or eform2db, rather the result of one’s browser navigation behavior negatively impacting a simplistic design (e.g. The main eForm2db example is very simple and not very cautious)