Dropdown field default item

Set a dropdown field default based on Joomla menu selection.

Overview

The dropdown in a CF form does not automatically reflect the user's menu choice.
Use custom PHP to detect the active menu item ID and assign the corresponding value to the form's data array for the dropdown field.

Answered
ja jaak 30 Dec, 2014
Hello,

I have Joomla menu with items:

Loan_type1, Loan_type2, Loan_type3

In the page i have dropdown list field on the form (the thirst page of the form inside module):
[list]Loan_type1
Loan_type2
Loan_type3[/list]

If the user selects "Loan_type2" from the menu, then "Loan_type2" should be automatically selected from the dropdown list. How would it be possible to do?

Jaak
es esl 30 Dec, 2014
This is the easiest way i know...
http://mywebsite.com/Car_Loans?Loan_type2=carloans
es esl 30 Dec, 2014
Correction http://mywebsite.com/Car_Loans?fieldname=Loan_type2
Gr GreyHead 31 Dec, 2014
Hi Jaak,

Presumably the ItemIds in the Menu URLs are different so you could use those to set the default value.

Bob
ja jaak 05 Jan, 2015
Hello,

Sorry if noob question.
I understand what I need to do, but how I can in Joomla to this variable to menu item.

Jaak
Gr GreyHead 06 Jan, 2015
Hi Jaak,

ChronoForms adds the URL variables to the $form->data array it uses - add a Debugger action temporarily to the On Load event of your form to see what values are there. You can set a variable either as esl suggests, or using the ItemId set by the menu. In the second case you will need some Custom PHP to link the ItemId to the Loan Type

Bob
ja jaak 06 Jan, 2015
Hello,

Exactly, my question was how it is possible to add get variable to Joomla menu. I manually probing to add needed variable to menu item and its working. But i can't found the way how to add variable to Joomla menu.

Jaak
ja jaak 07 Jan, 2015
Answer
Hello,

Solved.

I using code:

<?php
  //This is the code for the page with menu ID 766

$app = JFactory::getApplication();
$menuID = $app->getMenu()->getActive()->id;

  if ($menuID == 766)
  {
    $valik='pl';
    $form->data['laenuvalik'] = $valik;
 }
This topic is locked and no more replies can be posted.