Forums

How To Create Conditional Code For Dynamic Data DB Read

shamrick 04 Dec, 2014
I have successfully populated a drop-down field from a Dynamic Data DB Read using the instructions you provided here:

http://www.chronoengine.com/faqs/58-cfv4/cfv4-elements-and-html/2647-how-do-i-build-a-select-drop-down-radio-button-or-checkbox-group.html

I am currently pulling the item ID and title from a K2 items table. It works. However it's displaying all the items.

What snippet of code do I need to create a condition whereby only published K2 items are read in? (published field = 1)

I would also like the conditional code to only pull from a specified category. I have 6 categories (2 main categories with ID's 1,4 and 4 sub-categories with ID's 2,3,5,6). I would like the DB Read to pull only from category ID #1.

FYI, I tried the code < ?php return array('field' => 'value'); ?> populated with 'field' replaced by 'published' and 'value' replaced by '1' but it returned as a text string at the top of the form.

I also set Multi read to 'yes' in the Edit Action Settings.

Thank you,
Shannon
Max_admin 04 Dec, 2014
Hi Shannon,

You should use this code in the "Conditions" box:

<?php
return array("published" => 1);


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
shamrick 04 Dec, 2014
Max,

Thank you.

May I follow up with an additional question? How may I pass the text string title that's chosen into the email? It currently shows what looks like the ID #.
GreyHead 05 Dec, 2014
Hi Shannon,

Use a DB Read in the On Submit event to look up the title from the ID; or, if the titles are unique you could possibly use them in the drop-down instead of the id so the options would have both the value and text holding the titles,

Bob
shamrick 05 Dec, 2014
Bob,

Thank you for that. Unless I'm misunderstanding something, I do see the titles and not the ID's in the drop down box.

When the email is submitted, the ID shows as the value instead of the title itself.

Wondering if I needed a bit of php code in the email to pull the title? Or should I use another DB Read in the On Submit as you suggested?

Thanks.
GreyHead 05 Dec, 2014
Hi Shannon,

A drop-down has two parts to the data: the text - which you can see; and the value which is submitted but you can't see. Look at the page source to see them both.

Bob
Max_admin 06 Dec, 2014
Hi Shannon,

In this case you should enter "title" in both the "text" and "value" boxes under the "Dynamic data" tab in the dropdown settings!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
shamrick 08 Dec, 2014
Max,

Thanks. That did it. I'll just make sure that each K2 item has a unique title.
This topic is locked and no more replies can be posted.