ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Checkbox / Multiselect output

October 26, 2010 9:39pm

Subscribe [5]
  • #1 / Oct 26, 2010 9:39pm

    wjonthomas

    22 posts

    Is there any way to remove the commas from the checkbox and multiselect custom field output?

    I’m using a checkbox list to select words I want to add as class names on an HTML element.

    For instance, if I check web and print, my element will have class=“web print”.  Right now it is class=“web, print”.

  • #2 / Oct 26, 2010 11:15pm

    Sue Crocker

    26054 posts

    How about using one of the available find and replace plugins found on Devot-ee.com? Would that work for you?

  • #3 / Oct 27, 2010 11:03am

    wjonthomas

    22 posts

    That seems like overkill.  I may just have to implement my custom field differently somehow.  It’s kind of odd that EE is outputting a comma.  If they didn’t, I could choose to output the comma myself, so I don’t really see why EE does it.  Really limits usage and flexibility.

  • #4 / Oct 27, 2010 3:04pm

    Ingmar

    29245 posts

    I don’t think a plugin is overkill at all, although as little as one line of PHP could accomplish the same thing, of course… Moving to the CodeShare Corner.

  • #5 / Jan 13, 2011 10:08am

    Wayne Smallman

    176 posts

    Is there any way to remove the commas from the checkbox and multiselect custom field output?

    I’m using a checkbox list to select words I want to add as class names on an HTML element.

    For instance, if I check web and print, my element will have class=“web print”.  Right now it is class=“web, print”.

    Hi, you don’t need any additional components installing.

    First of all, alter the template preferences and enable PHP.

    Then, add the following to the top of the template:

    <?php
    
    $classes = '{custom_field_name}'; // assigning the custom field value to a PHP variable
    
    $classes = str_replace(",", "", $classes); // replacing the commas with nothing from the classes variable
    
    ?>

    Be sure to change {custom_field_name} for the name of your actual custom field name.

    Then, add the following to your HTML:

    <?php echo $classes; ?>

    That should work.

    If not, come back and let me know what happened (or didn’t happen, as the case may be).

  • #6 / Sep 07, 2013 4:19pm

    benwellby

    17 posts

    Hi Wayne,

    I know this is an old post, but perhaps this quick tip may be of use to someone…

    To get this to work rather than adding the first PHP block to the top of the page I had to put it within the channel entries tag, and then it worked perfectly.

    Thanks.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases