We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1061
    • 81 Posts
    I have in form multiselect options list. The Form handles itself. I need, after then I press submit, the multiselect list is been already had with the selected options.
    Chunk form:
    <form method="post" action="[[~[[+id]]]]" >
    	Product types:
    
    	<select size="7" multiple="multiple" name="prod_type[]">
    	    <option value="1" [[+prod_type:eq=`1`:then=`selected="selected"`:else=``]]>First</option>
    	    <option value="2" [[+prod_type:eq=`2`:then=`selected="selected"`:else=``]]>Second</option>
    	    <option value="3" [[+prod_type:eq=`3`:then=`selected="selected"`:else=``]]>Third</option>
    	    <option value="4" [[+prod_type:eq=`4`:then=`selected="selected"`:else=``]]>Fourth</option>
    	    <option value="5" [[+prod_type:eq=`5`:then=`selected="selected"`:else=``]]>Fifth</option>
    	    <option value="6" [[+prod_type:eq=`6`:then=`selected="selected"`:else=``]]>Sixth</option>
    	    <option value="7" [[+prod_type:eq=`7`:then=`selected="selected"`:else=``]]>Seventh</option>
    	</select>
    <input type=submit value=submit />
    </form>


    On snippet I tried to return selected options
    $FormOutput = $modx->getChunk($formTpl, array(
    'prod_type' => $_REQUEST['prod_type']
    ));
    


    In a result I have array. But nothing is selected.

    var_dump("$prod_type")
    ---
    array(3) {
    [0] => int(1)
    [1] => int(2)
    [2] => int(3) }

    If I remove "[ ]" (name="prod_type") then i get ONE selected(last selected on form).

    How I can return all selected options? [ed. note: alex_dutch last edited this post 12 years ago.]
      • 1778
      • 659 Posts
      hello
      did you try using $_POST instead of $_REQUEST ?
      Cheers
        • 1061
        • 81 Posts
        var_dump("$prod_type")
        --------------
        array(3) {
        [0] => int(1)
        [1] => int(2)
        [2] => int(3) }

        You see, $_REQUEST works fine.
          • 4172
          • 5,888 Posts
          try to change your snippet like that:

          $FormOutput = $modx->getChunk($formTpl, array(
          'prod_type' => implode(',',$_REQUEST['prod_type'])
          ));


          and the formitIsSelected-output-filter, which is included in the formit-package
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 1061
            • 81 Posts
            Did you mean
            /**
             * Custom output filter that returns checked="checked" if the value is set
             *
             * @var string $input
             * @var string $options
             * @package formit
             */
            $output = ' ';
            if ($input == $options) {
                $output = ' selected="selected"';
            }
            if (strpos($input,',') !== false) {
                $input = explode(',',$input);
                if (in_array($options,$input)) {
                    $output = ' selected="selected"';
                }
            }
            return $output;


            with output chunk
            <option value="[[+value]]" [[+selected]]>[[+text]]</option>
            [ed. note: alex_dutch last edited this post 12 years ago.]