List Field Type issue

11 posts by 3 authors in: Forums > CMS Builder
Last Post: June 3, 2009   (RSS)

Re: [g_williams] List Field Type issue

By ross - May 27, 2009

Hi there.

Thanks for posting!

It sounds to me like you want to list the options from that drop down menu on your site somewhere. If that's the case, I have some code for you try. Of course, I'd like to make sure I am on the right track here first though.

Basically, you have three options in a drop down in one of your sections. You would like to display those options on your site somewhere.

Let me know and we'll go from there. Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] List Field Type issue

By (Deleted User) - May 27, 2009

HI Ross

If you have a look at the HTML version i have done (link below) I am trying to replicate the "Materials Section:"
http://salixrw.com/projects/Timber_Basin_Glasgow.htm

Hope that helps understand my problem

Thanks
Gavin

Re: [g_williams] List Field Type issue

By ross - May 28, 2009

Hi Gavin

Thanks for the link but it isn't actually working for me. I don't think that will matter though as I just need to make sure of something in the admin interface anyway.

What I am wondering is if you had a drop down list in one of your sections and wanted to have the options from the drop down listed on your site somewhere.

Let me know :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] List Field Type issue

By (Deleted User) - May 29, 2009

Hi Ross

Yes I am using a drop down list in my Projects section its pulling the data from the Products section.

In the Admin > Section Editors > Projects it's set-up
Field Options
Display As: Pulldown (multi value)
List Options: Get options from database (advanced)
Section Tablename : Products
[font "Verdana"]Use this field for option values : "page file name"
Use this field for option labels : "name"


I'll give a quick over view what i've done it may help.

IN CMSBuilder
Currently i've set-up Products and Projects sections in the CMSBuilder and populated them.
In the Projects section I've created a Dropdown List(as shown above) which pulls in the products.
So when i populate a Project I can then select one or more Product(s) used for that project.

I am trying to show the information on the Projects detail page of the website.

Thank you again for your help.
Gavin

Re: [g_williams] List Field Type issue

By ross - May 29, 2009

Hi Gavin

I get it now :). Thanks!

Try this code out:

<?php $tags = explode(",", $record['products']); ?>

<?php foreach ($tags as $tag): ?>
<?php $trim_tag = trim($tag); ?>
<a href="<?php echo $trim_tag ?>.php"><?php echo $trim_tag; ?></a>,
<?php endforeach ?>


You may need to fiddle with that a bit but what it does it takes the values from that field (products) and displays the values one at a time. The link in my example will go to a page named the same a the option so you'll need to make sure those match up.

Let me know what you think ;).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] List Field Type issue

By (Deleted User) - May 29, 2009

Hi Ross thanks for getting back
I am looking forward to trying out first thing monday when i get back to work.

Just a quick question.
You mention it takes in the values from the field and displays them one at a time, then your using the value in the href and the linking word.
Is it possible to then use the label for the linking word?. for example <a href="Value">Label</a>
as the [font "Verdana"]Pulldown (multi value) allow you to select 2 different fields sources one for Labels and one for Values.

[font "Verdana"]I am asking this as initially when i set it up i thought i'd make it easy for my self and have the Values looking at a field 'page name' e.g. info entered. rock_rolls.php and the Label looking at the field 'product name' e.g. info entered. Rock Rolls. so when the information was pulled in on the details page it would show [font "Arial"]<a href="Value">Label</a>[font "Arial"]<a href="[font "Verdana"]rock_rolls.php">[font "Verdana"]Rock Rolls</a>


[font "Verdana"]Thanks for all your time helping out
regards
Gavin


[font "Verdana"]

Re: [g_williams] List Field Type issue

By ross - June 1, 2009

Hi Gavin

I see what you mean there. It will be tricky though. The main problem is that at this stage, the only thing being saved in your database is that one value so that's all we have to work with.

If you wanted to get quite a bite more advanced with the code, I think we could combine what I thought you need to start with and what we ended up with in my last post. It would likely be something we switch into a consulting project though as it's more than we can do in the forum.

Let me know what you think.
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] List Field Type issue

By (Deleted User) - June 1, 2009

Hi Ross

I think for simplicity I might look at your post and example code and work from there.
Can I ask your proffesional opinion before i wrote on the forum i found some useful pages and managed to knock together some code which i almost got the results i wanted. Would this ever work with some tweeks or should i give up? My PHP is limited thats why i decided to write for some help.

My Results as shown on website
/products/salixcell.php "Salix Cell"
/products/faggots_facines.php "Willow Faggots (Fascines)"
/products/c125.php "Salix Cell"
/products/coir_pallets.php "Willow Faggots (Fascines)"
/products/coir_rolls.php "Salix Cell"

As you can see the first 2 were ok and after that my loop goes wrong and just repeats the Label from the start.
The Code I used.

<?php $values = getListValues('projects', 'materials_used', $projectsRecord['materials_used']) ?>
<?php $labels = getListLabels('projects', 'materials_used', $projectsRecord['materials_used']) ?>
<?php $lastvalue = ' '; ?>

<?php foreach ($values as $value): ?>
<?php echo $value ?>
<?php foreach ($labels as $label): ?>
<?php if ($lastvalue != $label): ?>
<b><?php echo $label ?> </b>
<?php $lastvalue = $label; ?>
<?php break; ?>
<?php endif ?>
<?php endforeach ?>
<?php endforeach ?>

Thanks for all your help

Gavin

Re: [g_williams] List Field Type issue

By Dave - June 1, 2009

Hi Gavin,

Nice work so far!

It can be tricky to display values from multiple arrays. Try this:

<?php $values = getListValues('projects', 'materials_used', $projectsRecord['materials_used']) ?>
<?php $labels = getListLabels('projects', 'materials_used', $projectsRecord['materials_used']) ?>
<?php $valesToLabels = array_combine($values, $labels) ?>

<?php foreach ($valesToLabels as $value => $label): ?>
<a href="<?php echo $value ?>"><?php echo $label ?></a><br/>
<?php endforeach ?>


Assuming there isn't two values with the same "value" then that should work fine.

Give it a try and let me know! :)
Dave Edis - Senior Developer
interactivetools.com