Allow sending the ONLY ONCE form by the person identified

didimaga 20 May, 2016
Dear,
I am new to Joomla! and ChronoForms and please, I need help.

I created a form using ChronoForms v.5, to collect suggestions on the site.
The suggestion may be submitted by any visitor, but ONLY ONCE.
On the site visitors should inform some basic details like name, address, social security number (no official document), among others.

How to make the visitor can NOT send two suggestions?

I thought I'd check the CPF (which is a document that identifies each person - exclusive), but do not know how to do.

Obs .: My form is already programmed to record the data in the table.

I have attached a form image to clarify.

Any idea !?
Thank you very much.
GreyHead 20 May, 2016
Hi didimaga,

When the form submits you should check to see if the CPF is already in the table of saved data. If it is then show a message, if not go ahead and process the form. I'd use an Event Switcher action for that with a singe event defined called say 'duplicate'. In the Event Switcher add code like this
<?php
$db = \JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__some_table`
        WHERE `cpf` = '{$form->data['cpf']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
  return 'duplicate';
}
?>

In the On Duplicate event of the Event Switcher you can redirect to another page with a message about duplicate submissions.

You could also verify this before the form is submitted using JavaScript to make an AJAX call to check the CFO. This is quicker and more friendly but a bit harder to code. You's still need the Event Switcher check to confirm after submission.

Bob
This topic is locked and no more replies can be posted.