The problem is that the above code works anywhere else but not inside Custom Code action. Actually the first line ( $module = JModuleHelper::getModule('mod_webhotelier') ) returns an empty object. Is there any other way to retreive module params?Thanks,George"> How to retrieve module parameters to use them inside a form - Forums

Forums

How to retrieve module parameters to use them inside a form

gvouliakis 18 Mar, 2013
Hi,

I need to retrieve module parameters and update the document with a script defining a parameter of my main jQuery script that controls the form.

First I created a Custom Code action at the OnLoad event with the following code:

<?php
$module = JModuleHelper::getModule('mod_webhotelier');
$modparams = new JRegistry();
$modparams->loadString($module->params);
$sDate = $modparams->get('startdate');
$doc = JFactory::getDocument();
$doc->addScriptDeclaration('(function($){ $.startDate = "' . $sDate . '"; })(jQuery);');
?>


The problem is that the above code works anywhere else but not inside Custom Code action. Actually the first line ( $module = JModuleHelper::getModule('mod_webhotelier') ) returns an empty object.

Is there any other way to retreive module params?

Thanks,
George
GreyHead 18 Mar, 2013
Hi gvouliakis,

If you hunt through the Joomla! Docs you'll find a line of code to load the Module Helper, that should of what you need.

had a quick look . . . please try:
jimport( 'joomla.application.module.helper' );


Bob
gvouliakis 19 Mar, 2013
Dear Bob,

Thanks for your reply!
Before sending the issue I've already tried importing module helper class but the behavior was the same! An empty object is returned.

George
gvouliakis 19 Mar, 2013
Dear Bob,

SOLVED! SOLVED! SOLVED!

The module was not assigned to be displayed in the menu item that displays the form!!!! 😶
Now everything is Ok! I'm getting module params direct from modules table.


<?php
$db = JFactory::getDbo();
                
$query = $db->getQuery(true);
                
$query->select('module, params')
        ->from($db->quoteName('#__modules'))
        ->where( $db->quoteName('module') .' = '. $db->quote('mod_webhotelier'));
                
$db->setQuery($query);
                
$module = $db->loadObject();
                
$modParams = new JRegistry();
$modParams->loadString($module->params);
$sDate = $modParams->get('startdate');
$eDate = $modParams->get('enddate');
                
$doc = JFactory::getDocument();
                
$doc->addScriptDeclaration(';(function($){ $.sDate ="'.$sDate.'"; $.eDate="'.$eDate.'"; })(jQuery);');
?>


Thanks anyway for your time!

Regards,
George
GreyHead 19 Mar, 2013
Hi gvouliakis,

Well found :-) I wouldn't have though of that for a while.

Bob
This topic is locked and no more replies can be posted.