We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34144
    • 13 Posts
    Hi there,

    Got a little question for all the modx'ers out there.

    I want to achieve the following and I'm not sure which way to go, all in Revo 2.X

    In backoffice I want a Template var with checkbox inputs, so the admin of the site can select colors, no problem there, just choose the input controller to be a checkbox and the options in this format, option1==green||option2==red,...

    So far so good. In the template that builds the page I want to display the selected colors in a drop down menu. As part of a form.

    Something like this:

    <select name="select" id="select">
    <option value="green">green</option>
    <option value="red">red</option>
    </select>

    So when admin selects more or less colors, the dropbox has to choose the right colors.

    How to I manage this? Probably writing a snippet of my own, but I'm kinda lost there

      • 4172
      • 5,888 Posts
      try:

      [[!prepareSelect? &values=`[[*colorsTV]]` &name=`color`]]


      with a snippet like that:

      <?php
      
      $values = str_replace(',','||',$values);//in case the values are commaseparated, convert the delimiters to doublepipes
      $values = explode('||', $values);
      $output = '';
      
      if (count($values) > 0) {
      
          $output = '<select name="'.$name.'" id="'.$name.'">';
      
          foreach ($values as $value) {
              $selected = $_REQUEST[$name] == $value ? 'selected="selected"' : '';
              $output .= '<option ' . $selected . ' value="' . $value . '">' . $value . '</option>';
          }
      
          $output .= '</select>';
      
      }
      
      return $output;
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 34144
        • 13 Posts
        Great thanx, I will try it.