Multi Value Checkbox List Problem

9 posts by 3 authors in: Forums > CMS Builder
Last Post: November 20, 2009   (RSS)

By (Deleted User) - September 29, 2009

Hello,

I am having trouble displaying some guides when selected from a multi value checkbox list.

Ok,
I have a list with a field name of 'guides'
The list is display as 'checkboxes (multi value)'
The list options are:
alex|Alex
ben|Ben
sarah|Sarah

I wanted it so that if no guides were checked the heading wouldn't display at all. The heading comes and goes if any of the names are checked or not - that's fine.

But nothing shows for the actual names. Can you help me? Also is there a better way to display this - with elseif for example??

In the php page I have the following code.

<?php foreach ($guided_tourRecords as $record): ?>
<?php if ($record['guides']): ?>
<h4>Guides Available: </h4>
<?php endif ?><?php endforeach; ?>

<?php foreach ($guided_tourRecords as $record): ?>
<?php if ($record['guides'] == 'alex'): ?>Display Alex stuff
<?php endif ?> <?php endforeach; ?>

<?php foreach ($guided_tourRecords as $record): ?>
<?php if ($record['guides'] == 'ben'): ?>Display Ben stuff
<?php endif ?> <?php endforeach; ?>

<?php foreach ($guided_tourRecords as $record): ?>
<?php if ($record['guides'] == 'sarah'): ?>Display Sarah stuff
<?php endif ?> <?php endforeach; ?>


Thanks Jono

Re: [jonoc73] Multi Value Checkbox List Problem

By Chris - September 29, 2009 - edited: September 29, 2009

Hi Jono,

Multi-value list field values are stored as a tab-separated list, surrounded by tabs (e.g. "\talex\tsarah\t", where "\t" is a tab.) This makes it easy to search for a value like this:

<?php if (strpos($record['guides'], "\t" . 'alex' . "\t") !== false): ?>Display Alex stuff
<?php endif ?>


To make things more readable and easy to update, I've written "\talex\t" as "\t" . 'alex' . "\t".

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Multi Value Checkbox List Problem

By Chris - September 29, 2009 - edited: September 29, 2009

Also, I'm not sure how exactly you want to structure your page, but I'm guessing you probably don't need that many foreaches. Try this instead?

<?php foreach ($guided_tourRecords as $record): ?>

<?php if ($record['guides']): ?>

<h4>Guides Available: </h4>

<?php if (strpos($record['guides'], "\t" . 'alex' . "\t") !== false): ?>
Display Alex stuff
<?php endif ?>

<?php if (strpos($record['guides'], "\t" . 'ben' . "\t") !== false): ?>
Display Ben stuff
<?php endif ?>

<?php if (strpos($record['guides'], "\t" . 'sarah' . "\t") !== false): ?>
Display Sarah stuff
<?php endif ?>

<?php endif ?>

<?php endforeach; ?>

All the best,
Chris

Re: [chris] Multi Value Checkbox List Problem

By (Deleted User) - September 29, 2009

Chris, you are a star - that works great!

I am brand new to CMS Builder and boy I wish I had moved over years ago!

Until Friday I used Wordpress as my CMS - I have built loads of clients sites with Wordpress but no longer! The CMS Builder gives much more steam-lined cleaner code and wow the pages load loads quicker. Plus as your reply shows - there is GREAT customer service too!

Really pleased I became part of the Interactive Tools users! Next site I build you can bet it will be with another CMS Builder.

Thanks Jonathan

Re: [chris] Multi Value Checkbox List Problem

By (Deleted User) - September 29, 2009

MM, Although this lists most of the names, one or two slip through the net and aren't listed. I have re-checked their field names and they are correct, I have also checked there are no strange spaces in the list, again nothing.

The strange thing is if I choose some other names the ones that didn't list before do list - can't accurately track it down.

Any clues?

Jono

Re: [chris] Multi Value Checkbox List Problem

By (Deleted User) - September 29, 2009

Woo Hoo, it works fine now.

Thanks
Jono

Re: [jonoc73] Multi Value Checkbox List Problem

By MRI - November 19, 2009

i have a similar issue... how do I display if multiple items are checked off?

Re: [MRI] Multi Value Checkbox List Problem

By Chris - November 20, 2009

Hi MRI,

This is a duplicate post of http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/Multiple_Check_box_list_P75964/ , right?
All the best,
Chris