1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

PHP plugin in form not working

Discussion in 'Community' started by rajpawar, May 21, 2020.

  1. rajpawar

    rajpawar New Member

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

    troester Well-Known Member Staff Member

    Level: Community
    Use var_dump() or the jDump extension to debug what you really get in your variables.
    Add line by line etc.
    e.g.
    the code after return true; will never be run
     
  3. rajpawar

    rajpawar New Member

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

    troester Well-Known Member Staff Member

    Level: Community

Share This Page