SOLVED: Validation on php form plugin

Status
Not open for further replies.

dimoss

Well-Known Member
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
 
if you do :

PHP:
$db->setQuery($query);
echo $query->dump();
exit;
what is the query that is generated?
 
Hi Rob

This is the query produced:
Code:
SELECT COUNT(*)
FROM fab_table
WHERE etos =  AND minas =

This is incorrect as it doesn't pass the variables' values.
 
It looks like $etos and $minas are empty, check with var_dump

What do you want to validate? onAfterProcess the record is already stored.
 
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!
 
Thanks Troester :)
However in which position I need to put it?
After the if statement?
Sorry if it's a stupid question!
 
Hi Troester

It works ok with the message appeared as expected.
I put it before 'return false'
Thanks a lot!
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top