Usefull data from arrays

faitas 11 Sep, 2014
Hello there,
following this faqhttps://www.chronoengine.com/faqs/63-cfv4/cfv4-working-with-form-data/3222-how-can-i-get-useful-data-from-select-drop-downs-checkboxes-and-radio-buttons.html here I created the following script in a custom element

<?php
$appliances_array = array(
S_Refrigerator => 'Small Refrigerator (<100lt)',
L_Refrigerator => 'Large Refrigerator (>100lt)',
TV => 'TV (LCD)',
Radio => 'Stereo (DVD, Radio, CD, etc)',
Satellite => 'Satellite',
Fan => 'Air fan',
PC => 'PC',
Few_lights => 'Few Lights (<5)',
Many_lights => 'Many Lights'
);

$appliances_names = array();
foreach ( $form->data['appliances'] as $v ) {
  $appliances_names[] = $appliances_array[$v];
}

$form->data['appliances_names'] = implode(', ', $appliances_names);
?>


but when I place {appliances_names} the data is not showing.

any idea?
faitas 11 Sep, 2014
none of the above! 😟
GreyHead 12 Sep, 2014
Hi faitas,

You need quotes round both parts of the array entries. So use
  'S_Refrigerator' => 'Small Refrigerator (<100lt)',
with quotes round S_Refrigerator and the same for all the others.

Bob
faitas 12 Sep, 2014
Tryied that as well, it is not working!

<?php
$appliances_array = array(
'S_Refrigerator' => 'Small Refrigerator (<100lt)',
'L_Refrigerator' => 'Large Refrigerator (>100lt)',
'TV' => 'TV (LCD)',
'Radio' => 'Stereo (DVD, Radio, CD, etc)',
'Satellite' => 'Satellite',
'Fan' => 'Air fan',
'PC' => 'PC',
'Few_lights' => 'Few Lights (<5)',
'Many_lights' => 'Many Lights'
);

$appliances_names = array();
foreach ( $form->data['appliances'] as $v ) {
  $appliances_names[] = $appliances_array[$v];
}
$form->data['appliances_names'] = implode(', ', $appliances_names);
?>
GreyHead 12 Sep, 2014
i faitas,

The code looks OK - what do you see when you add a Debugger action after that?

Bob
faitas 12 Sep, 2014
This is what I see:

Array
(
    [option] => com_chronoforms
    [chronoform] => off-grid_system_SHOW
    [sunray] => 14
    [language] => en-GB
    [Itemid] => 
    [lang] => en
    [cf_id] => 14
    [cf_uid] => 05db5ed7212a020c8a3b922b83a648ff
    [cf_created] => 2014-07-07 07:35:03
    [cf_ipaddress] => 62.103.76.60
    [cf_user_id] => 2901
    [firstname] => testing 
    [Last_Name] => maniak
    [email] => cfaitatzoglou@gmail.com
    [phone] => 454454661
    [latitude] => 39.147103
    [longitude] => 29.827881
    [location] => Kütahya Province, Turkey
    [radio_type] => medium
    [area] => 45
    [period] => summer
    [use_days] => weekends
    [appliances] => L_Refrigerator,Fan,PC
    [terms] => 1
    [vcode] => da0039ea66b9988b4eb2e34ef3f51d33
    [vstatus] => 1
    [notes] => 
)
Validation Errors: 
Array
(
)
GreyHead 12 Sep, 2014
Hi faitas,

It looks as though you have a Handle Arrays action before the Custom Code action, Please try moving the Custom Code action so that is runs before the Handle Arrays.

Bob
faitas 12 Sep, 2014
my events are as in the attached picture. I do not have any handle arrays action ... should I?

[attachment=0]Capture.JPG[/attachment]
GreyHead 12 Sep, 2014
HI faitas,

I'm sorry but I have no idea what you are trying to do here :-(

If there is nothing in the On Submit event where are you trying to show these values?

Bob
faitas 12 Sep, 2014
I show data out of the database.
GreyHead 12 Sep, 2014
Hi faitas,

In that case the saved data
 [appliances] => L_Refrigerator,Fan,PC 
needs to be converted back into an array before your PHP will work on it.

Bob
faitas 12 Sep, 2014
ok. can you give me a hint please :? on how to do it?
GreyHead 12 Sep, 2014
Answer
1 Likes
Hi Faitas,

Please try
$form->data['appliances'] = explode(',', $form->data['appliances']);

Bob
faitas 12 Sep, 2014
rock 'n roll ....

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