Setting up an amenity list using checkboxes

9 posts by 2 authors in: Forums > CMS Builder
Last Post: December 23, 2009   (RSS)

HI, I am wanting to set up a amenity checkbox list in the admin that can be used for the different properties I need to show.

For instance, I would have a list like this (below) in the admin that I could select from and if it has a checkbox (1) - it would display on the property detail page. If it does not have a checkbox (0), it would not be displayed.

How would I go about setting that code up or are their any examples that I can look at?

--------------

Sleeps
2
4
6
8
10
12

Entertainment
TV’s
1
2
3
4
5

Cable
HD
Satellite
Dish
Direct TV

Flat Screen
Wide Screen

Surround Sound

VCR
DVD
CD

Communication
Local Calls
Unlimited Long Distance

High Speed Internet
Wireless Internet

Bed Size:
Master
King
Queen
Double
BR 2
King
Queen
Double
Twin

Re: [drewh01] Setting up an amenity list using checkboxes

By Chris - December 21, 2009

Hi drewh01,

For checkboxes, you can create a checkbox field, then paste in the following code into your detail page:

<?php if ($propertyRecord['surround_sound']): ?>
Surround Sound<br />
<?php endif ?>


You'll need to change the code in red above to match your record variable name, field name, and HTML you want to display if the field is checked.

Some of your examples (e.g. Bed Size) would probably make more sense as List fields instead of Checkbox fields. To display the value of a list field, you need only paste in this code:

<?php echo htmlspecialchars($propertyRecord['bed_size'])) ?>

Once again, replacing the text in red with your record variable name and field name.

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

Re: [chris] Setting up an amenity list using checkboxes

great, thanks for that.

My other question is regarding formatting for the front end (display). How do I keep the unchecked value from adding a space from the page viewer?

For instance, if I have 3 checkbox items in the admin and only check the 1st and 3rd checkbox, I get a blank space between them.

IN ADMIN (backend)
item 1 (checked)
item 2
item 3 (checked)

IN DISPLAY VIEWER (front end)
item 1

item 3

Hope that makes sense.

Here is a test page I made up:

http://www.sedonaeliteproperties.com/test-checkbox.php

(Look below the metadescription field on that page)

As you can see DVD and CABLE TV has a space between them. That is where I suppose CD would go if it was checked in the admin.

Re: [drewh01] Setting up an amenity list using checkboxes

By Chris - December 21, 2009

Hi drewh01,

The trick here is to put your <br /> before the <?php endif ?>, that way the linebreak will only appear if the checkbox is checked.

Does that solve the problem?
All the best,
Chris

Re: [chris] Setting up an amenity list using checkboxes

ah yes...so simple.

:-)

Re: [drewh01] Setting up an amenity list using checkboxes

I get an error using the list code:

Sleeps: <?php echo htmlspecialchars($furnished_propertiesRecord['sleeps'])) ?>

http://www.sedonaeliteproperties.com/test-checkbox.php

Re: [drewh01] Setting up an amenity list using checkboxes

When using the list code, how do I make it so when there is no value the item will not appear on the display page?

Re: [drewh01] Setting up an amenity list using checkboxes

By Chris - December 23, 2009

Hi drewh01,

If you have code like this for a list field:

Bed Size: <?php echo htmlspecialchars($propertyRecord['bed_size'])) ?>

You need only wrap it in an IF block to hide it when there's no option selected:

<?php if ($propertyRecord['bed_size']): ?>
Bed Size: <?php echo htmlspecialchars($propertyRecord['bed_size'])) ?>
<?php endif ?>


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