PHP plugin in form not working

rajpawar

New Member
Hi all! I am trying to validate data in the form prior to submitting the form with existing data in the database. Basically I am comparing "start time", "end time" and "date" to see if an entry with those conditions already exists. The records get added without any errors or validation. I have searched various forums and wrote the code based on that, but it may have errors. Please help!! My PHP plugin is set to (OnBeforeProcess). Here is the code

if (!$formModel->isNewRecord()) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$thisStartTime = $formModel->formData['table___start_time'];
$thisEndTime = $formModel->formData['table___end_time'];
$thisDate = $formModel->formData['table___date'];
$query->select(COUNT('*'))->from('table')->where('start_time >= ' . $db->quote($thisStartTime) and 'end_time <= ' . $db->quote($thisEndTime) and 'date = ' . $db->quote($thisDate));
$db->setQuery($query);
$count = $db->loadResult();
if ($count > 0)
{
return true;
$formModel->getForm()->error = "An Assignment for that time and date already exists";
}
}
return false;
 
Use var_dump() or the jDump extension to debug what you really get in your variables.
Add line by line etc.
e.g.
return true;
$formModel->getForm()->error = "An Assignment for that time and date already exists";
the code after return true; will never be run
 
Thanks for your response. All I get using the var_dump() is
string(9) "MY_VAR : " NULL

Is there a syntax error in my code?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top