BreezingForms

 

Here it is explained how to set Ajax validation for a field in a form so that if a user tries to submit the form with the same value which was already submitted in that form an error message is shown. 

In the following example, an email field NAMED "email" is being validated.

To implement this to your form, follow these steps:

1. Go to Properties of the field that you wish to validate. In the Validation section check the "Required" checkbox and set the Validation type to "Custom". In the code are below that appears, put the following code:

function ff_email_validation(element, message)
{
    if(ff_validemail(element, message) != '') return 'Please enter an email address';
    var myreturn = '';
    JQuery.ajaxSetup({async:false});
    JQuery.post('index.php', { option: 'com_breezingforms', ff_form: ff_processor.form, Itemid: 0, format: 'html', email: element.value }, function(data){ if( data != '1' ){ message == '' ? myreturn = 'Email exists already!' : myreturn = message; } } );
    return myreturn;
}

 NOTE: Replace every instance of email with the name of that field in your form that you wish to validate. Also, you can replace "Email exists already" with whatever message you want.

2. Go to the Advanced properties of the field that you wish to validate. In Actionscript section set Type to Custom and Action to Change. In the code below put the following code:

function ff_email_action(element, action)
{
    switch (action) {
        case 'change':
            JQuery('#bfEmailError').remove();
            if(element.value == '') return;
            var myreturn = '';
            JQuery.ajaxSetup({async:false});
            JQuery.post('index.php', { option: 'com_breezingforms', ff_form: ff_processor.form, Itemid: 0, format: 'html', email: element.value }, function(data){ if( data != '1' ){ myreturn = '<div class="bfError" id="bfEmailError"></div>'; } else { myreturn = ''; } } );
            if(myreturn != '') { JQuery(element).after(myreturn); } else { JQuery('#bfEmailError').remove(); }
            break;
        default:;
    } // switch
} // ff_email_action

 NOTE: Replace every instance of email with the name of that field in your form that you wish to validate.

3. Go to form's Advanced properties > More options > Form pieces and in the Before Form section set Type to Custom and in the code area below put the following code:

if( JRequest::getVar('email', null) !== null ){
   while (@ob_get_level() > 0) {
    @ob_end_clean();
   }
   $db = JFactory::getDBO();
   $db->setQuery("Select s.id From #__facileforms_records As r, #__facileforms_subrecords As s Where s.record = r.id And r.form = ".$this->form." And s.`value` = " . $db->Quote(JRequest::getVar('email', null)));
   if(trim($db->loadResult())){
     echo 0;
   } else {
     echo 1;
   }
   exit;
}

NOTE: Replace every instance of email with the name of that field in your form that you wish to validate.

4. Go to form's Advanced properties > More options > Submit pieces and in the Begin Submit section set Type to Custom and in the code area below put the following code:

$this->execPieceByName('ff_InitLib');
$db = JFactory::getDBO();
$db->setQuery("Select s.id From #__facileforms_records As r, #__facileforms_subrecords As s Where s.record = r.id And r.form = ".$this->form." And s.`value` = " . $db->Quote(ff_getSubmit('email')));
if(trim($db->loadResult())){
 exit;
}

NOTE: Replace email with the name of that field in your form that you wish to validate.

That will do the trick, your form will throw an error message saying "Email exists already" in case you try to submit the form with email address (or another info) that way already submitted.

 

To sum up, this is how to disable user to submit the form with the same value twice in a specific form field. You can apply this for email or username, or another field that you need. Above is explained how to apply this to a field in your form.

 

 

Special Offer

Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!