- Details
- Category: Blog
- Published: Wednesday, 11 September 2019 13:08
- Written by Mihaela
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.
- Details
- Category: Blog
- Published: Thursday, 22 August 2019 12:15
- Written by Mihaela
Here it is explained how to apply Advanced List Filter in Content Builder on a Select List element when the "Multiple" checkbox is checked so that more options can be select at a time.
If Advanced List Filter is applied on a multi-select list and Filter is defined as follows, it will only search for records where only one value was selected, for example only value1.
value1
value2
value3
It will not show records that have both values value1 and value3 and as selected values, or value1 and value2.
To see all records that include a certain value of a multi-select list, possibly along with some other value, define the Filter as listed below:
@match/value1
@match/value2
@match/value3
After defining the filter this way, all records including the value searched for will be shown.