Forums

Howto pass a parameter to a form

jinx52 09 Apr, 2015
Hi, I'm trying to upgrade a site from Joomla 1.5 / Chronoforms V4 to Joomla 3.4.1 / Chronoforms V5.
On the old site I had one form that would load items from a database based on the parameters sent from the menu item.
I had a DB Multi Loader on the form and in the option for the WHERE statement I had the following;

<?php
$token = $form->data['token'];
$where = array();
if ( $token ) {
  $where[] = "`input_listing_type` = '{$token}'";
}
$where = implode(' AND ', $where);
echo $where;
?>
 ORDER BY PerformerDetails.input_performing_name


Then I had different menu items, of type External URL, each with a different token value. So when the user selected a menu item, the URL would be something like

index.php?option=com_chronoforms&chronoform=showperformerlisting&token=1


The form would read the token value and only display database records that matched.

I am trying to replicate this under Joomla 3 / Chrono 5 and can't make it work. I can't see where to add a parameter to a Chronosforms menu item and I'm unsure of the code to put in the new form layout.

Any help would be greatly appreciated.

Thanks,

Nick
GreyHead 09 Apr, 2015
Hi Nick,

I'm not sure why the option setting got dropped :-(

In Joomla! 3 with CFv5 you can get the Menu ID with a custom code action and use that to set your values.

In a Custom Code action you can use either of these snippets to get the menu iD
<?php
$menu_id = JRequest::getVar('Itemid');
?>

<?php
$app = JFactory::getApplication();
$menu_id = $app->getMenu()->getActive()->id;
?>
The second one also lets you get more info if you need it.

I would probably convert this to a token using an included file (that way you can include the same file in several forms).
<?php
include (JPATH_SITE.'/components/com_chronoforms5/includes/menu_ids.php');
?>
The file would just need an array that you can use to look up a token from a Menu ID
<?php
$menu_ids = array(
  'Some_id' => 'some token',
 . . .
);
?>

Then putting that together
<?php
$menu_id = JRequest::getVar('Itemid');
include (JPATH_SITE.'/components/com_chronoforms5/includes/menu_ids.php');
$form->data['token'] = $menu_ids[$menu_id];
?>

Bob
jinx52 15 Apr, 2015
Worked like a charm - thanks Bob!
This topic is locked and no more replies can be posted.