[SOLVED] Products Module - Displaying a checkbox field

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
fearmydesign
Power Poster
Power Poster
Posts: 363
Joined: Sun Feb 28, 2010 10:54 pm

[SOLVED] Products Module - Displaying a checkbox field

Post by fearmydesign »

Hello, I have created several Checkbox options inside the Products Module additional Fields tab. I am using the latest 1.11.6 CMSMS

I am trying to check which of the Checkboxes is checked and then display its value (The Name). Here is the code on my summary template:

Code: Select all

     <div id="title">
          {if count($entry->fields)}
            {foreach from=$entry->fields key='name' item='field'}
                
               {if $field->type == 'checkbox' && isset($field->value)}
                 <p style="font-size:10px; color:#ff0000; margin:0px; padding:0px;">{$field->name}</p>
               {/if}

            {/foreach}
          {/if}

     </div>
I am not an expert on Smarty but I have tried to modify this line of code but doesn't work.

Code: Select all

{if $field->type == 'checkbox' && isset($field->value == true)}

Code: Select all

{if $field->type == 'checkbox' && $name == 'Checkbox'}

Code: Select all

{if $field->type == 'checkbox'}
I looked at the Smarty if statement functions http://www.smarty.net/docsv2/en/language.function.if but can't seem to figure out how to implement this. Can anyone help me or point me in the right direction?

Thank you
Last edited by fearmydesign on Tue Apr 23, 2013 2:45 pm, edited 1 time in total.
User avatar
fearmydesign
Power Poster
Power Poster
Posts: 363
Joined: Sun Feb 28, 2010 10:54 pm

Re: Products Module - Displaying a checkbox field

Post by fearmydesign »

I can't figure out how to check which 'Checkbox' is checked (true) and to then display the corresponding Name of that Checkbox... this is the code I just tried...

Code: Select all

{if $field->type == 'checkbox'}
                <p style="font-size:10px; color:#ff0000; margin:0px; padding:0px;">{$field->name}</p>
             {/if}
Please see the left column of the site to see what I am referring to... the red 'Partner' label underneath each attorney is what I am trying to change... there are 4 options (i.e. Partner, Associate... etc.)

http://ileansolutions.com/ditthavong/in ... =attorneys

But it does NOT display the Checkbox that is checked...
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Products Module - Displaying a checkbox field

Post by Wishbone »

Seems to work for me if I use:

Code: Select all

{if $field->type == 'checkbox' && $field->value=='true'}
Note: isset() doesn't work for $field->value because it's always set to 'true' or 'false' (strings, not booleans)

....but I don't see what's wrong with the page.. I see several attorneys, and their titles, so I might be missing the point.

Why the underscores in the titles? I know that $field->name can't have spaces, but $field->prompt can.
User avatar
fearmydesign
Power Poster
Power Poster
Posts: 363
Joined: Sun Feb 28, 2010 10:54 pm

Re: Products Module - Displaying a checkbox field

Post by fearmydesign »

Wishbone wrote:Seems to work for me if I use:

Code: Select all

{if $field->type == 'checkbox' && $field->value=='true'}
Note: isset() doesn't work for $field->value because it's always set to 'true' or 'false' (strings, not booleans)

....but I don't see what's wrong with the page.. I see several attorneys, and their titles, so I might be missing the point.

Why the underscores in the titles? I know that $field->name can't have spaces, but $field->prompt can.
Thank you, so I was on the right track with what I wanted to do but not quite there, also I was calling the name of the checkbox field and NOT the prompt as you stated, this fixed it! Thank you so much for your help. Corrected;

Code: Select all

{if $field->type == 'checkbox' && $field->value=='true'}
                 <p style="font-size:10px; color:#ff0000; margin:0px; padding:0px;">{$field->prompt}</p>
               {/if}
Post Reply

Return to “Modules/Add-Ons”