Hi - I’m trying to add a duplicate check function into eform2db to make sure a user can only submit the form one time and I can’t seem to get it to work. Here is the code I’m using. The sql returns the right result
<?php
function entry2db( &$fields )
{
global $modx;
//check if already entered
$sql = "select * from `modx_entries` where `email` = ’".$fields[’email’]."’");
$result = $modx->db->query($sql);
return $result;
$num = mysql_num_rows($result);
if( $num > 0 )
{
// Set placeholders
$chunkArr = array(’dupe_entry’ => ’It appears you have already entered the contest. Only one entry per person is allowed. If you have a question or feel there is a problem please contact us at <a href="mailto:
[email protected]">
[email protected]</a>. Thank you.’);
Output the dupe alert
echo $modx->parseChunk( ’dupe_entry_tpl’, $chunkArr, ’[+’, ’+]’ );
// Prevent form load
return true;
}else
{
// Init our array
$dbTable = array();
$dbTable[name] = $fields[name];
$dbTable[email] = $fields[email];
$dbTable[highschool] = $fields[highschool];
$dbTable[address] = $fields[address];
$dbTable[address2] = $fields[address2];
$dbTable[city] = $fields[city];
$dbTable[state] = $fields[state];
$dbTable[zip] = $fields[zip];
$dbTable[phone] = $fields[phone];
$dbTable[idea] = $fields[idea];
// Run the db insert query
$dbQuery = $modx->db->insert($dbTable, ’modx_entries’ );
return true;
}
}
?>
Any help greatly appreciated