Joomla!

Allowing visitors to only submit a form once using Chronoforms 3

Written by Ian Carnaghan · 42 sec read >
  1. Click on the form name under the Forms Management tab and ensure that Data storage is enabled
  2. Next click on the Validation Tab
  3. Scroll down to the Server Side Validation and set Enable Server Side Validationto yes
  4. In the text area Server Side Validation Code add the following code
    <?php
     
    $db =& JFactory::getDBO();
     
    $query = "
     
      SELECT count(*)
     
        FROM `jos_chronoforms_table`
     
        WHERE `text_9` = ".$db->Quote($_POST['text_9']).";
     
      ";
     
    $db->setQuery($query);
     
    if ( $db->loadResult() ) {
     
    return "You've already entered this competition";
     
    }
     
    ?>

    Replace jos_chronoforms_table with the table name where you are storing the form submission data.

    In the code above we validate the user against the field_9 column in the database table jos_chronoforms_table, if the value entered already exist injos_chronoforms_table in the field_9 column it means the user has submitted the form.

    Our field_9 in the above example contains the email address, so if the entered email address exist in the table in means that the user already submitted the form

    The global variable $_POST[‘text_9’] contains the form field text_9’s value that the user entered.

    You may want to replace field_9 with your column to check against.

Last Updated On March 25, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. In my spare time I teach undergraduate classes in web development. Profile

Leave a Reply

avatar
  Subscribe  
Notify of