Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
注册失败的Joomla插件事件_Joomla_Joomla2.5 - Fatal编程技术网

注册失败的Joomla插件事件

注册失败的Joomla插件事件,joomla,joomla2.5,Joomla,Joomla2.5,我有许多指向用户注册组件的菜单。根据用户注册的位置,我使用自定义插件相应地重定向它们 public function onUserAfterSave($user, $isnew, $success, $msg) { //get the active menu item id so we can compare what plan we are on $menu = $app->getMenu(); $active = $menu->getActive

我有许多指向用户注册组件的菜单。根据用户注册的位置,我使用自定义插件相应地重定向它们

public function onUserAfterSave($user, $isnew, $success, $msg)
{

    //get the active menu item id so we can compare what plan we are on
    $menu   = $app->getMenu();
    $active   = $menu->getActive();
    $activeId = $active->id;

    //compare active page (i.e. what menu item are we on) with the parameter set in the plugin
    //if it matches redirect accordingly - fallback is to always redirect to free plan
    if ($activeId == $this->params->get('free-reg-menu'))
    {
        //redirect required to go to main page
        JFactory::getApplication()->redirect(JRoute::_('page1'));
    }
    else if ($activeId == $this->params->get('bv-reg-menu')) 
    {
        //redirect to step 2 of main plan payment processing
        JFactory::getApplication()->redirect(JRoute::_('page2'));
    }
    else if ($activeId == $this->params->get('prem-reg-menu'))
    {
        //redirect to step 2 of value plan payment processing
        JFactory::getApplication()->redirect(JRoute::_('page3'));
    }
    else
    {
        //other stuff
    }

}
根据插件中分配的菜单,我将用户重定向到特定页面。这一切都很有效

我的问题是当注册失败时(即重复的用户名、错误的匹配密码等),由于服务器端验证,页面会刷新。此刷新会使页面脱离原始链接。它似乎重定向到我创建的第一个注册菜单页面


例如:我在注册页面上,输入了错误的凭据,然后页面刷新到完全不同的页面。有什么想法吗?我想AJAX注册的扩展可能会解决这个问题,但我现在想避免这种情况。

您可以执行以下操作:

  • 改为在路线后的内执行检查
  • 将结果保存在用户会话中
  • 结果成功后,从onUserAfterSave执行重定向
我想不出一个更简单的方法来做这件事,也想不出有什么复杂的地方


系统插件
肯定是@WooDzu坚持了下来。关键无疑是会话变量。但我所做的是创建一个组件,它只做一件简单的事情。基于url创建会话变量,并使用我提取的查询字符串。因此,可以通过以下方式访问我的组件:

www.mysite.com/index.php?option=com\u mycomp&task=registration&plan=

然后,我的组件有一个简单的控制器,看起来像:

function registration()
{
    $jinput = JFactory::getApplication()->input;
    $plan = $jinput->get('plan', null, 'STRING');

    $session = JFactory::getSession();
    $session->set('plan', $plan);

    if ($plan == "page1")
    {
        JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=registration&plan=page1'));
    }
    else if ($plan == "page2")
    {
        JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=registration&plan=page2'));

    }
    else 
    {
        JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=registration&plan=page3'));
    }

}
这将重定向到设置了会话变量的com_用户注册组件。然后我用
OnUserAfterSave
将插件安装到位,但它会根据会话变量而不是菜单ID或别名重定向


我不知道这是否是最好的方法,但它看起来确实相当干净。

我想你的意思是将if语句中的
重定向
替换为将结果存储在用户参数中?你要怎么做?嗨。我已经更新了我的答案来展示一个例子。我还没有测试过它,但它应该能让你对这个想法有一个大致的了解。我不认为这是可行的。如果用户在注册字段中输入错误,它将永远不会触发
onUserBeforeSave
。验证在这之前进行。我需要一种方法来触发注册失败。这是一个很好的观点。您可能需要另一个插件从系统文件夹来实现这一点,并在一个AfterRoute事件检测提交的表单请参阅我的更新答案。现在应该可以了,试试吧
<?php
public function onUserAfterSave($user, $isnew, $success, $msg)
{
    $session = JFactory::getSession();

    if ($finalRedirect = $session->get('my.redirection')
        && $success == true
        && $isnew == true)
    {
        // Clear the session entry
        $session->set('my.redirection', null);

        JFactory::getApplication()->redirect($finalRedirect);
    }
}
function registration()
{
    $jinput = JFactory::getApplication()->input;
    $plan = $jinput->get('plan', null, 'STRING');

    $session = JFactory::getSession();
    $session->set('plan', $plan);

    if ($plan == "page1")
    {
        JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=registration&plan=page1'));
    }
    else if ($plan == "page2")
    {
        JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=registration&plan=page2'));

    }
    else 
    {
        JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=registration&plan=page3'));
    }

}