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.

processing a coma separated list

February 08, 2012 1:31pm

Subscribe [2]
  • #1 / Feb 08, 2012 1:31pm

    Shan Ricciardi

    18 posts

    Hi i need to find a way to turn a coma separated list within a custom field (text-area) to output into a set of form parameters and options.
    Currently I am using pixel and tonics list field type. My client does not like having to enter one option at a time and prefers a simple list to mange. She has already created the list and wants to cut and paste them into the textarea. A list would look like so:

    wine, magenta, purple, blue, teal, turquoise, green, olive, apple, rust, chocolate

    Within my template outputs to:

    <option value="wine">wine</option>
     <option value="magenta">magenta</option>
     <option value="purple">purple</option>
     <option value="blue">blue</option>
     <option value="teal">teal</option>
     <option value="turquoise">turquoise</option>
     <option value="green">green</option>
     <option value="olive">olive</option>
     <option value="apple">apple</option>
     <option value="rust">rust</option>
     <option value="chocolate">chocolate</option>


    I think there is a way to do this with the defalut install of EE 2. I am unaware of how to do such processing.
    My current solution is to use the (pixel and tonic) List field type. My template code looks like this:

    </select> <input type="hidden" name="on1" value="Color"> <select name="os1">
     <option value="">
     -- Choose a color --
     </option>
     {product_colors}
     <option value="{item}">
     {item}
     </option>
     {/product_colors}

     
    Any help would be greatly appreciated.
    Thanks,
    Shan Ricciardi

  • #2 / Feb 09, 2012 4:00pm

    Dan Decker

    7338 posts

    Hi Shan,

    You can either use PHP in your template to explode the list, or you can use a plugin that can build your options for you based on the field.

    Let me know what you think!

    Cheers,

  • #3 / Feb 09, 2012 4:53pm

    Shan Ricciardi

    18 posts

    Thanks Dan! The plugin you mentioned works but it outputs all entries in my database. I just want to show one entry per tag.

    I am a newbie with PHP. I did try the explode function. I did not get it working. What would I need to set PHP Parsing Stage to? Output or Input?

    Thanks again,

    Shan Ricciardi

  • #4 / Feb 09, 2012 7:30pm

    Shan Ricciardi

    18 posts

    I was able to get this working with PHP explode function. I set my template to PHP Parsing Stage to Output. I used the following code:

    {exp:channel:entries channel="products" disable="member_data|pagination" sort="asc" }
    <?php
    $sizeOptions = "{product_sizes}";
    $colorOptions = "{product_colors}"; 
    $sizeChunks = explode(",", $sizeOptions);
     ?>

    With my option fields set up like this:

    <select name="os0">
    <?php
    for($i = 0; $i < count($sizeChunks); $i++){
    echo "<option value='$sizeChunks[$i]'>$sizeChunks[$i]</option> ";
    }
    ?>                         
    </select>
    <select name="os1">
    <?php
    for($i = 0; $i < count($colorChunks); $i++){
    echo "<option value='$colorChunks[$i]'>$colorChunks[$i]</option> ";
    }
    ?>
    </select>

    Thanks for you help!

    Shan Ricciardi

  • #5 / Feb 13, 2012 1:23pm

    Shane Eckert

    7174 posts

    Hello rdesigns,

    I am happy to see you found the solution!

    I appreciate you posting your solution. The community is benefited by it.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases