// Add jQuery cookie plugin
JFactory::getDocument()->addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js');
// Get filter parameters from session
$app = JFactory::getApplication();
$start = $app->getUserState('com_jevents.filter.startdate', '');
$end = $app->getUserState('com_jevents.filter.enddate', '');
$catid = $app->getUserState('com_jevents.filter.catid', '');
$virtualtxt = $app->getUserState('com_jevents.filter.virtual', '');
$matchtxt = $app->getUserState('com_jevents.filter.match', '');
// If form is submitted, update session state
if ($app->input->getMethod() == 'POST') {
$start = $app->input->get('startdate', '', 'STRING');
$end = $app->input->get('enddate', '', 'STRING');
$catid = $app->input->get('catid', '', 'STRING');
$virtualtxt = $app->input->get('virtualtxt', '', 'STRING');
$matchtxt = $app->input->get('matchtxt', '', 'STRING');
$app->setUserState('com_jevents.filter.startdate', $start);
$app->setUserState('com_jevents.filter.enddate', $end);
$app->setUserState('com_jevents.filter.catid', $catid);
$app->setUserState('com_jevents.filter.virtual', $virtualtxt);
$app->setUserState('com_jevents.filter.match', $matchtxt);
// Redirect to clean URL
$app->redirect(JRoute::_('index.php?option=com_jevents&view=list&layout=events&Itemid=109'));
return;
}