setQuery($query);$count = $db->loadResult();if ( $count > 0 ) {$form->validation_errors['codice_fiscale'] = "This client id already exists.";return false;}?>"> CF5 - Validate field "live" from select mysql "Data already exist on db" - Forums

Forums

CF5 - Validate field "live" from select mysql "Data already exist on db"

andreasuriani 19 Oct, 2017
Hi All.
First of all, i'm not a programmer🙂 I'm using Joomla and CF5 to create a Company's Intranet.

I've learned many things about php js, css ecc ecc and i'd like to do this on my form:

I've field called "codice_fiscale" (it's a italian unicode for people).
Workers have to input this code into the form to add it on Database.
I'd like to check if the data is already exist on the db but not on submit (i know to do it) but after leave the field.

Is it possible?

I've tried to follow this topic https://www.chronoengine.com/forums/posts/t92827/validate-on-existence-client-id-from-database but no result....

The code that i have created is this:

<?php
include "file_include/master.php";

$query = "
SELECT COUNT(codice_fiscale)
FROM $ana_dip_generale
WHERE `codice_fiscale` = '{$form->data['codice_fiscale']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
$form->validation_errors['codice_fiscale'] = "This client id already exists.";
return false;
}
?>
GreyHead 20 Oct, 2017
Hi andreasuriani,

The code you found does a check after the form is submitted, not when the input is completed. To have it work the way you want you will need to add a Custom Validation to that input and the validation will need to make an AJAX call back to the server to query the database. If you are not familiar with JavaScript you will probably needs some help to do that.

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