Forums

Value for 'selected' in form wizard (drop down) from a php variable?

tondorius03 12 Feb, 2014
Hi,
i wrote a interface between chronoform and sobi pro. It works fine but for drop down lists one problem occurs.
I have a php string variable (extern script) which holds the selected option value from a sobi pro drop down list called $selected_value. I want to place the value of this variable in the selected-field in the form wizard so that the option value ist automatically selected in chronoform.

Variable from sobi pro:
$selected_value="blue";

Drop down list in chronoform:
blue="blue";
yellow="yellow;"

-> blue must be automatically selected

I can't write directly php code in the selected field in the form wizard for example:
Selected: <?php echo "$selected_value"; ?>

Is there a way to solve this problem?

thanks & regards!!
JM
GreyHead 12 Feb, 2014
Answer
Hi JM,

If you add it to the $form->data array then the ChronoForms republisher should do what you need.
<?php
$form->data['input_name'] = $your_variable;
?>
tondorius03 12 Feb, 2014
You are great!
I bought a "beer-ticket" on your website;-) Cheers!
JM
andrea74 16 Apr, 2014
Hi,
I'm using CF V5 and I have the same problem, but I don't understand how to use the array trick.
In the "Option" field I put:

GENERAL=General Information
TANUR=Tanur
REF=REF


and in "Selected Values" field:

<?php echo $_GET["product"]; ?>


but doesn't work. (if I stamp the variable "product" I can correctly see the value).
Could you help me please?
Thank you in advance.
Max_admin 16 Apr, 2014
Hi Andrea,

what's the name of your select field ? assuming its "product" then simply add a "custom code" action before the HTML action and use Bob's code!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
andrea74 17 Apr, 2014
Dear Max,
if "info_on" is the name of the select field and "product" the name of variable, I put in Setup->JavaScript->JS Code the string
<?php
$form->data['info_on'] = $product;
?>

without success.
Is it necessary to put something in "Selected Values" field of the select (Edit element settings window)?
Thank you for the support.
andrea74 17 Apr, 2014
I also try to move the code
<?php
$form->data['info_on'] = $product;
?>

in a Custom Code field (Designer->Advanced), but it still does not work.
GreyHead 17 Apr, 2014
Hi Andrea,

The value of $product needs to be set - it won't magically appear. Using Joomla! 2.5+ the code will need to be something like:
<?php
$jinput = JFactory::getApplication()->input;
$product = $jinput->get('product', '', 'STRING');
$form->data['info_on'] = $product;
?>

Bob
andrea74 17 Apr, 2014
Thank you very much Bob, I could not have solved without your help.
This topic is locked and no more replies can be posted.