Page 1 of 1

[SOLVED] Products Module - Displaying a checkbox field

Posted: Mon Apr 22, 2013 10:37 pm
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

Re: Products Module - Displaying a checkbox field

Posted: Tue Apr 23, 2013 12:40 am
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...

Re: Products Module - Displaying a checkbox field

Posted: Tue Apr 23, 2013 1:36 am
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.

Re: Products Module - Displaying a checkbox field

Posted: Tue Apr 23, 2013 2:45 pm
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}