• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

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

No members online now.
Back
Top