Check to avoid double records in the DB

How to prevent duplicate form submissions in ChronoForms.

Overview

The issue occurred because custom PHP code placed in the 'Before emails code' section was not properly integrated with the form's validation process.
Enable the form's Advanced settings and use the built-in Custom Serverside Validation tool to check for existing records before allowing a submission.

Answered
SP SPABO 17 Mar, 2016
Hi Bob,

I have put the following code in the tab Others/Custom PHP code/Before emails code
<?php
$naam = JRequest::getString('naam', '', 'post');
$email1 = JRequest::getString('email1', '', 'post');
if ( $naam && $email1) {
  $db =& JFactory::getDBO();
  $query = "
    SELECT COUNT(*)
      FROM `vs2cm_chronoforms_data_xxxx`
      WHERE `naam` = '{$naam}'
        AND `email1` = '{$email1}';
  ";
 $db->setQuery($query);
  $count = $db->loadResult();
  if ( $count > 0 ) {
    $form->validation_errors[''] = "U heeft dit formulier reeds ingevuld!";
    return false;
  }}
?>


However, it does not work and I can keep sending out the completed form with the same input

Pls advise

Rgds
K
SP SPABO 18 Mar, 2016
Answer
Hi Bob,
I chaanged teh settings to Advancxed, and now I could add the Custom Serverside Validation tool.
Now it works fine!

Best rgds
K
This topic is locked and no more replies can be posted.