Forums

Dynamic select box - Pull article titles

momentis 12 Mar, 2012
I need to create a dynamic select box on a form. This select box will pull the titles of published articles from a specific category from the Joomla content table. I found the following forum post which speaks to this:

http://chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=20013&p=60824&hilit=dynamic+dropdown#p60824

This was posted in 2010. I am wondering if CFv4 has a feature to do this in a different way, perhaps through the wizard interface? My query to populate the select box is:

SELECT title FROM #__content WHERE catid = 34 AND state = 1

Thanks!!!
GreyHead 12 Mar, 2012
Hi Rick,

This came at an opportune time. I've just been working on a Custom Select [GH] action that lets you use pre-defined option lists in Select drop-downs, checkbox and radio groups.

You can see a demonstration here (unfortunately this site was installed with no content to I had to do a quick add of a couple of articles for that drop-down. More information is here where you can also get the action.

This will be a paid action but as it's fresh off the press there are five free copies available with this coupon SN9Ky#6eSY

Bob

PS Here's the result from using the custom option on my local test site where the sample content is installed:
#CONTENT:WHERE `catid` IN (19,26) AND `state`=1#
momentis 12 Mar, 2012
You are AWESOME!!!! Thanks, and I did download the doc using the coupon code. I will make up for it by buying you a beer instead 🙂
GreyHead 12 Mar, 2012
Hi Rick,

Thank you - do let me know if you find any bugs. I have already thought that I should add a curly replacer to the #CONTENT# syntax so that you could (if you needed to) change the search parameters using from data.

Bob
momentis 13 Mar, 2012
I am not able to get this to work. With debugging, I can see that the array is being populated with the correct article titles. However, they are not appearing in the select box. Here is the page:

http://hysonproducts.com/index.php?option=com_chronoforms&chronoform=career_application

I named the Data Path (in the custom action) job_select. On the form field, I enabled Dynamic Data and put job_select in the Data Path field. There is nothing in the Value Key or Text Key fields.

What step am I missing?
GreyHead 13 Mar, 2012
Hi Rick,

You need value in the Value Key box and text in the Text Key box.

Bob
momentis 14 Mar, 2012
Ahh, well that would make a difference! Thank you SO much!!
cjmicro 24 May, 2012
Hi Bob, thanks SO MUCH for that greyhead.net tutorial. I have one little problem. When the emails are processed it is showing the article ID number, not the name. The dropdown populated fine and changes as the articles change. I had to modify slightly for joomla 2.5. (catid instead of sectionid)

Here is my code:
<?php
$options = array();
$options[] = "<option value=''>--?--</option>";
$db =& JFactory::getDBO();
$query = "
  SELECT `id`, `title`
    FROM `spfx_content`
    WHERE `catid` = 22
      AND `state` = 1  
      ORDER BY `title`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
foreach ( $data as $d ) {
  $options[] = "<option value='{$d->id}'>{$d->title}</option>";
}
?>
<select class="" id="job" size="1" name="job">
<?php echo implode("\n", $options); ?>
</select>


The field name is job, and i have {job} in the email template, but it returns the article id #. Any suggestions?

Thanks!
Cheryl
GreyHead 25 May, 2012
Hi Cheryl,

If you have the ID then you can look up any other information about the article with a DB query and the id is unique while the title may not be.

To get the title from the id:
$db =& JFactory::getDBO();
$query = "
    SELECT `title`
        FROM `#__content`
        WHERE `id` = '{$form->data['id']}' ;
";
$db->setQuery($query);
$title = $db->loadResult();
Replace $form->data['id'] with the form input that holds the article id.

Bob
cjmicro 25 May, 2012
Thanks for the reply. I'm using the code from your tutorial for the article title drop down (which I pasted in my earlier message). I was going to just use a field and grab the article title, but I think your dropdown is a better option for this application.

In the form the dropdown is working fine, but when the results are emailed,the ID # of the article shows instead of the title. That's the only problem I'm having now.

the end of the code
<select class="" id="job" size="1" name="job">
<?php echo implode("\n", $options); ?>
</select>


in my email template i have Position Desired: {job}

but it's putting the id, and i need it to show the title.

Thanks for any assistance.
Cheryl
GreyHead 25 May, 2012
Hi Cheryl,

You can always put the title into the options - but I wouldn't there are too many chances for odd characters to break the code. Instead look it up when you need it - the code for this is in my reply to your other post on this topic.

Bob
cjmicro 25 May, 2012
I saw the other code, just not sure how to integrate it with my drop down code. Can that code go in the email template?

cheryl
GreyHead 25 May, 2012
Hi Cheryl,

It could go in the Email template but neater in a Custom Code action before the Email action.

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