简体   繁体   English

Joomla 3.2从模块获取表单组件

[英]Joomla 3.2 get form component from module

I created a module that get a form of a component but it works only in the pages of the component. 我创建了一个获取组件形式的模块,但是它仅在组件页面中有效。

My class module helper : 我的班级模块助手:

class ModReservationHelper
{
    public static function &getForm()
    {
       jimport('joomla.application.component.model');
       JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_booking/models');
       $Model = JModelLegacy::getInstance( 'ReservationForm', 'BookingModel' );

        return $Model->getForm();
    }
}

The form return only on the component page, i need the form in all page .... 表单仅在组件页面上返回,我需要所有页面中的表单....

You can use another method: 您可以使用另一种方法:

// create new JForm object
$myForm = new JForm('MyForm');

// Load any form .xml file you want (like registration.xml)
$myForm->loadFile(JPATH_ROOT.'/components/com_users/models/forms/registration.xml');

Now you can render this object like any other Joomla! 现在,您可以像其他任何Joomla一样渲染此对象! form (foreach ($myForm->getFieldsets() as $fieldset), etc.). 形式(foreach($ myForm-> getFieldsets()为$ fieldset)等)。 Remember to add suitable option and task fields and form.token of course. 请记住,当然要添加适当的选项任务字段以及form.token

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM