Validation - check if value exists in another table

Parcs

New Member
Hi, I have a multipage form, on the first page there is only a field where the user should insert a number.
I would like to add a validation to this field that should check if the number inserted exists in another table of the database (which is another Fabrik form table).

In other words, I need to check if the number inserted by the user in 'table2___user_code' field exists in 'table1___id' column. If the number exists the field is validated and the user can proceed to the second page of the form, otherwise validation should fail and user can't go on.

Is that possible?
Thank you
 
Thank you troester, I know php validation is the way, but I don't know what is the php expression to achieve what I need. I made some tests trying the common tasks you linked, but it seems I can't figure it out.
I am not a developer and I'm very poor in php. Could you please send me in the right direction?
 
Something like this should do:
Code:
$mydb = JFactory::getDBO();
$mydb->setQuery("SELECT id FROM table1 WHERE id = ".$mydb->Quote($data));
$myresult = $mydb->loadObjectList();

if ($myresult) {
  return true;
}
P.S. This exact code is not tested. var_dump $data and $myresult if you have problems.
 
Last edited:
If you want to use more then "out of the box" Fabrik you'll have to know about MySQL, php, HTML, CSS, JS...
Something like
Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
    ->select('count(*)')
    ->from('table1')
    ->where('id = ' . $myDb->quote($data));//the validated element's value is in $data

$myDb->setQuery($myQuery);
$mycount = $myDb->loadResult();
return (bool)$mycount;

Edit: as you can see there are multiple ways to skin a cat;)
 
Can one ever have enough options? :p
Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select($myDb->quoteName('id'))
    ->from($myDb->quoteName('table1'));
$myDb->setQuery($myQuery);
$allvalues = $myDb->loadColumn();
return in_array($data, $allvalues);
Poor cat...
 
Last edited:
Thanks to all of you, all the suggested solutions perfectly suit my needs... the cat is skinned!
Troester, I know I need to improve my knowledge to get the best from Fabrik, Html css and MySql are not a problem, but when it comes to php I know I still got a lot to learn...

Thank you again!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top