Forums

How to add a custom array as datasource of dropdown

Collie-IT 01 Aug, 2020
Dear Support,

in Version 5 and 6 chronoforms was able to set a custom array as source of dropdown list.
like
v5
$form->data['dropdown'] = array(...);
v6
$this->data['dropdown'] = array(...);
How is this behavior posible in Chronoforms 7?

Best regards
Collie-IT
Max_admin 03 Aug, 2020
use the options or multiline settings for a list of defined options!

If you want a dynamic list of options, from a PHP action for example, then use {var:php_name} in the "data source" of the "Dynamic options"
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Collie-IT 10 Aug, 2020
Dear Max,

My problem is that I have informations in 3 tables stored and need a custom SQL read (Wordpress, user, user_blocked and user_meta).The user_meta table writes values to a user_id like this

id user_id valuename value
1 3 name Test
1 3 vorname Teo
1 2 name otto

The problem is that I can't build the querry via data read.
My Solutuion is to generate with PHP an string and save it as variable
$args = array(
'exclude' =>$blockedUser,
'role' => 'Berater',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$user = get_users( $args );

$counselors ="";
foreach($user as $key =>$councelor){

$counselors = $counselors . "\n" .$councelor->data->ID . " = " . $councelor->data->display_name;
}

$this->set("counselors", $counselors);
Use the multiline setting.


and then I have modifide chronoforms7\chronog3\admin\extensions\chronofc\behaviors\views\field_multiline_options\field_multiline_options_output.php to following

<?php
if(!empty($unit['multiline_options'])){

[color=rgb(255, 0, 0)][strong] $gtext=$unit['multiline_options'];
if( substr($unit['multiline_options'], 0, 5) === "{var:"){
$gtext = $this->controller->Parser->parse($unit['multiline_options']);
}[/strong][/color]

$lines = explode("\n", $gtext);

$lines = array_map('trim', $lines);
$lines = array_filter($lines, 'strlen');

foreach($lines as $line){
$option = [];
$odata = explode('=', $line);

$option = [
'value' => $odata[0],
'content' => $this->controller->Parser->parse($odata[1] ?? $odata[0]),
];
[br] $unit['foptions'][] = $option;[br] }[br] }
Feel free to use this solution
Max_admin 10 Aug, 2020
you better return an array from the PHP and use the "Dynamic options" instead, write {var:counselors} in the "Data sources", and set the paths to the value and text with the {var:path_to_value_in_the_array_item}

so you should return an array in this structure:
$options = array(['value' => 1, 'text' => 11], ['value' => 2, 'text' => 22]);

then you would use {var:value} and {var:text} for the option data!

please confirm this solution works for you ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Collie-IT 10 Aug, 2020
The problem was that {var:counselors} not worked. I tryed to make a data Read first know the $unit['data_source'] stick with 22 and the
{var:counselors} will not be saved.
Max_admin 11 Aug, 2020
so my solution did not work for you ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Collie-IT 11 Aug, 2020
Yes out of the reason you solution not worked.
This topic is locked and no more replies can be posted.