How to display multi-value checkbox comma seperated or CSS

4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 9, 2014   (RSS)

By andybarn - July 24, 2014

I have a Real Estate Website

Please can you tell me how to display items from a multi-value checkbox correctly;

In cmsAdmin, I use a field called 'features' set as multi-value checkbox and let's say someone checks the list of items like this:

[x] item 1
[x] item 2
[ ] item 3
[ ] item 4
[ ] item 5
[x] item 6
[ ] item 7
[x] item 8

In listingDetail.php I put in

<?php echo $listing['features'] ?>

and it would display the results like this:

item 1 item 2 item 6 item 8

I have two questions,

  1.  What would I put in listingDetail.php if I want to display them like this (comma separated):

    item 1, item 2, item 6, item 8

  2.  Ideally I would like to use CSS which displays icons, copy of the html on how I would want it to look after it had been processed below:-

<span class="features">               
<span class="color-green"><i class="fa fa-check-square-o"></i></span>item 1 
<span class="color-green"><i class="fa fa-check-square-o"></i></span>item 2 
<span class="color-green"><i class="fa fa-check-square-o"></i></span>item 6
<span class="color-green"><i class="fa fa-check-square-o"></i></span>item 8
</span>


What code would I put in listingDetail.php if I want to display the items like the above?

More Information:

At the top of my listingDetail.php file I have the following code:-

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
  require_once "init.php";

  list($listingRecords, $listingDetails) = getRecords(array(
    'tableName'   => 'listings',
    'joinTable'   => 'homepages',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $listing = @$listingRecords[0];


  if (!$listing) { print "Listing not found!"; exit; }

?>

 
I have spent hours on this so any help appreciated.

Thanks
Andy

By andybarn - July 27, 2014

Hi Greg

Thanks for your reply. I managed to achieve what I wanted doing it a different way using the php echo join command.

Below is my code

                <div class="headline"><h3>Property Features</h3></div>
                <i class="fa fa-check-square-1st"></i><?php echo join('<i class="fa fa-check-square-o"></i>',$listing['features:values']); ?><br/>

The class

<i class="fa fa-check-square-1st"></i>

creates the first tick box and the following code below

<?php echo join('<i class="fa fa-check-square-o"></i>',$listing['features:values']); ?>

uses the css code (which creates the other tick boxes) instead of a comma which is normally used the the comma separated list of features.

As I say, this works for me, though probably not as elegant as your suggested code.

Thanks for looking into this for me.

Andy

By andybarn - August 9, 2014

Hi Greg

Just a quick update.

I was finding my code a bit limiting, so reverted back to your code which was far more flexible.

Your code worked straight away and with a little modification,  I managed to achieve exactly what I wanted.

Thanks very much again for your help.

Kind Regards

Andy