Validate on existence client ID from database

bierhuis 27 Nov, 2013
Hello,

I made a simple form with Chronoforms / joomla 2.5. When submitted fields are validated, the data is mailed and stored in a database table.

What I would like is before the form is submitted and maild etc. there will be a check if the client id (one field in the form) exists in a data base table. And otherwise gives an error message 'you client id isn't recognized. Please try again'

Is this possible in Chronoforms? Or can I catch de data in the redirect page (e.g. php page)

Thanks, Bert
GreyHead 27 Nov, 2013
Hi bierhuis,

You can do this with PHP using a Custom Serverside Validation action to do the check.
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT COUNT *
    FROM `#__some_table`
    WHERE `client_id` = '{$form->data['client_id']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
  $form->validation_errors['client_id'] = "This client id already exists.";
  return false;
}
?>

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