jform object from plugin to view

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
pirosoft
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Feb 20, 2017 10:35 am

jform object from plugin to view

Post by pirosoft » Mon Feb 20, 2017 10:40 am

Hi, i have this problem, in a plugin i load a jform object:

Code: Select all

 public function getForm() {        
        $form = &JForm::getInstance('content', __DIR__ . '/forms/content.xml');

        foreach ($form->getFieldsets('main') as $fieldsets => $fieldset):
            echo "main<br />";
            foreach ($form->getFieldset($fieldset->name) as $field):
                echo "field<br />";
                // If the field is hidden, only use the input.
                if ($field->hidden):
                    echo $field->input;
                else:
                    echo $field->label;
                    echo $field->input;
                endif;
            endforeach;
        endforeach;        
    }
in my view:

Code: Select all

       JPluginHelper::importPlugin('ecart');
      $dispatcher = JEventDispatcher::getInstance();
      $form = $dispatcher->trigger('getForm');
and so it's all ok!


now, i want use the code of foreach in the view so:

Code: Select all

 public function getForm() {        
       $form = &JForm::getInstance('content', __DIR__ . '/forms/content.xml');
       return $form;        
 }
and in the default.php in my view:

Code: Select all

                    JPluginHelper::importPlugin('myplugin');
                    $dispatcher = JEventDispatcher::getInstance();
                    $form = $dispatcher->trigger('getForm');

                    foreach ($form->getFieldsets('main') as $fieldsets => $fieldset):
                        echo "main<br />";
                        foreach ($form->getFieldset($fieldset->name) as $field):
                            echo "field<br />";
                            // If the field is hidden, only use the input.
                            if ($field->hidden):
                                echo $field->input;
                            else:
                                echo $field->label;
                                echo $field->input;
                            endif;
                        endforeach;
                    endforeach;
but this give a error:
fatal error: Call to a member function getFieldsets() on array in ..../default.php on line 161

why?
if i make a print_r of $form give:
Array ( [0] => JForm Object ( [data:protected] => Joomla\Registry\Registry Object (.....

thanks

pirosoft
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Feb 20, 2017 10:35 am

Re: jform object from plugin to view

Post by pirosoft » Wed Feb 22, 2017 9:30 am

help?

pirosoft
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Feb 20, 2017 10:35 am

Re: jform object from plugin to view

Post by pirosoft » Wed Feb 22, 2017 9:53 am

thanks, I solved the problem.

soevind
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Thu Oct 12, 2017 11:05 am

Re: jform object from plugin to view

Post by soevind » Mon Feb 05, 2018 3:45 pm

pirosoft wrote:thanks, I solved the problem.
How ?


Locked

Return to “Joomla! 3.x Coding”