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
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
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.
Chris
Re: [chris] Multi Value Checkbox List Problem
By Chris - September 29, 2009 - edited: September 29, 2009
<?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; ?>
Chris
Re: [chris] Multi Value Checkbox List Problem
By (Deleted User) - September 29, 2009
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
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: [jonoc73] Multi Value Checkbox List Problem
By Chris - September 29, 2009
I've updated the code above (the change is in blue) to properly catch items at the beginning of the list.
I must have still been asleep when I posted, sorry about that!
Chris
Re: [chris] Multi Value Checkbox List Problem
By (Deleted User) - September 29, 2009
Thanks
Jono
Re: [jonoc73] Multi Value Checkbox List Problem
By MRI - November 19, 2009
Re: [MRI] Multi Value Checkbox List Problem
By Chris - November 20, 2009
This is a duplicate post of http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/Multiple_Check_box_list_P75964/ , right?
Chris