I created a new rule for my own form. This rule should check, if username exists and if user is in one of specified groups.
Can you help me?
<?php
defined('_JEXEC') or die('Restricted access');
class JFormRuleUser extends JFormRule
{
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
// TODO: check if username exists and if user is in one of these groups: X, Y and/or Z
return false;
}
}
Use the JUserHelper class like
$id = JUserHelper::getUserId();
if ($id)
{
if (in_array(JUserHelper::getUserGroups($id), $groupsToCheck))
{
return true;
}
}
return false;