Forums

Display form from template file

AloneAngel 25 Mar, 2015
Hello,

I'm trying to display the form I've created on the user profile page.
Actually, it should appear hidden so I could display it in BS3 modal when user will click a button.
The form is working fine, but I don't know how can I embed form inside User Profile page using PHP.
I was trying to include it using plugin and just outputting
{chronoforms5}form_name{/chronoforms5}
from my template, but this didn't work. I saw just {chronoforms5}form_name{/chronoforms5} as a plain text on my user page.
Also, I've found recommendation on this forum to use something like:

require_once( JPATH_SITE.DS.'components'.DS.'com_chronocontact'.DS.'libraries'.DS.'chronoform.php');
$formname = 'some form name';//if left empty then it will be grabbed from the URL
$MyForm =& CFChronoForm::getInstance($formname);
$MyForm->showForm($formname);

I've tried to search all the code of Joomla for
function showForm
but nothing was found. So, I think it was changed in CFv5

Could you suggest me how can I display my form using PHP from Joomla template?
Max_admin 25 Mar, 2015
Hi AloneAngel,

The easiest solution in this case is to use a Joomla module, most probably your template has one above the content or below it, where you can display your form.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
AloneAngel 25 Mar, 2015
Hello, Max,

First of all I would like to thank you for your support and fast reply.

Actually, the part of the template where I want to put my form doesn't have module positions at all.
I'm using Profiler module to change the view of user profile page. And using this module I'm able only to use overwrite functionality to update the template. So, there are no module positions at all and I'm doing changes directly in the code of this so-called "template" (actually, it's just a view function).
Do you think it's possible to output form using PHP code?

I got 1 dirty solution by just adding the code of CFv5 plugin function that returns form somewhere and calling it. Thanks god, plugin is very small and the function that makes rendering of the form is small as well. But I don't like this solution very much as far as it will produce code duplication and I was searching for the cleaner way of doing this. I like really much the solution you've proposed some time ago on this forum with
showForm
function, but I didn't succeed to make it working.
Max_admin 25 Mar, 2015
The code here was for v3, here is the code for v5:

jimport('cegcore.joomla_gcloader');
ob_start();
$output = new JoomlaGCLoader('front', 'chronoforms5', 'chronoforms', array("chronoform" => "FORM_NAME"), array('controller' => '', 'action' => ''));
$return = ob_get_clean();
echo $return;


But an easier solution would be to ask the Profiler developer how to use content plugins in the view code and just use the Chronoforms5 plugin short code.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
AloneAngel 26 Mar, 2015
Hello, Max,

I've tried executing your code but as soon as I call
 $output = new JoomlaGCLoader('front', 'chronoforms5', 'chronoforms', array("chronoform" => "FORM_NAME"), array('controller' => '', 'action' => ''));
I'm getting an empty page.

I've tried another way by loading plugin and calling it's method. Here's my code:
JPluginHelper::importPlugin('content', 'chronoforms5');
$dispatcher =& JDispatcher::getInstance();
$form = $dispatcher->trigger('render_item', array('profile-information'))[0];

And after that I can output my form where I want by just calling:
echo $form;


What do you think about this approach? Cannot it produce some unexpected errors or increase load on the site?

Thank you.
Max_admin 26 Mar, 2015
Well, I'm not sure of the 2nd solution, but if it does work then fine, just test that all the form features work as expected, like validation and emails..etc

Regarding the empty page, this is usually a PHP error, if you set the "error reporting" to maximum under the Joomla global config then it should display the error.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.