1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    Dismiss Notice

Validation - check if value exists in another table

Discussion in 'Community' started by Parcs, Jul 16, 2021.

  1. Parcs

    Parcs New Member

    Level: Community
    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
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
  3. Parcs

    Parcs New Member

    Level: Community
    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?
  4. juuser

    juuser Well-Known Member

    Level: Community
    Something like this should do:
    Code (Text):
    $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: Jul 16, 2021
    hominid4 and lousyfool like this.
  5. troester

    troester Well-Known Member Staff Member

    Level: Community
    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 (Text):
    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);

        ->where('id = ' . $myDb->quote($data));//the validated element's value is in $data

    $mycount = $myDb->loadResult();
    return (bool)$mycount;
    Edit: as you can see there are multiple ways to skin a cat;)
    hominid4, lousyfool and juuser like this.
  6. lousyfool

    lousyfool Active Member

    Level: Community
    Can one ever have enough options? :p
    Code (Text):

    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);
    $allvalues = $myDb->loadColumn();
    return in_array($data, $allvalues);
    Poor cat...
    Last edited: Jul 17, 2021
    hominid4 and juuser like this.
  7. Parcs

    Parcs New Member

    Level: Community
    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!

Share This Page