1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice
  2. If you update to Joomla 3.9.16, you will have to update Fabrik from the latest GitHub version, to fix a bug introduced in Joomla, which makes it impossible to list front end folder locations in backend JForms. This affects things like template selection.
    Dismiss Notice

SOLVED: Validation on php form plugin

Discussion in 'Standard Support' started by dimoss, Sep 24, 2015.

Thread Status:
Not open for further replies.
  1. dimoss

    dimoss Well-Known Member

    Level: Community
    Hi

    I use the following code on a php form plugin to validate the record insertion on a table onAfterProcess:

    PHP:

    $etos = $formModel->getElementData('fab_mitroo_elegktwn___etos', true);if (is_array($etos)) {$etos = $etos[0];}
    $minas = $formModel->getElementData('fab_mitroo_elegktwn___minas', true);if (is_array($minas)) {$minas = $minas[0];}
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->select('COUNT(*)');
    $query->from('fab_table');
    $query->where('etos = '.$etos);
    $query->where('minas = '.$minas);
    $db->setQuery($query);
    $number = $db->loadResult();
    if ($number > 0)
    {
    return false;
    }
    else
    {
    return true;
    }
     
    However it seems that something is wrong as the real query should return > 0 which means 'false'.
    Any help is appreciated.

    Thanks
     
  2. rob

    rob Administrator Staff Member

    Level: Community
    if you do :

    PHP:

    $db->setQuery($query);
    echo $query->dump();
    exit;
     
    what is the query that is generated?
     
  3. dimoss

    dimoss Well-Known Member

    Level: Community
    Hi Rob

    This is the query produced:
    Code (Text):
    SELECT COUNT(*)
    FROM fab_table
    WHERE etos =  AND minas =
    This is incorrect as it doesn't pass the variables' values.
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    It looks like $etos and $minas are empty, check with var_dump

    What do you want to validate? onAfterProcess the record is already stored.
     
  5. dimoss

    dimoss Well-Known Member

    Level: Community
    Hi Troester

    The query was empty because it was m y mistake with the naming...:oops:
    You are right with onAfterProcess. I did it with onBeforeProcess and worked which means it didn't record but I got the normal message that the record added/updated.
    Why is that? Is there any way to hide this message and get a pop up or something which says that record is not added blah...blah.... ?
    Thanks!
     
  6. troester

    troester Well-Known Member Staff Member

    Level: Community
  7. dimoss

    dimoss Well-Known Member

    Level: Community
    Thanks Troester :)
    However in which position I need to put it?
    After the if statement?
    Sorry if it's a stupid question!
     
  8. troester

    troester Well-Known Member Staff Member

    Level: Community
    Yes, before return false;
     
    dimoss likes this.
  9. dimoss

    dimoss Well-Known Member

    Level: Community
    Hi Troester

    It works ok with the message appeared as expected.
    I put it before 'return false'
    Thanks a lot!
     
Thread Status:
Not open for further replies.

Share This Page