We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43864
    • 151 Posts
    In a posthook I'm using getvalue to retrieve the values of a form. For normal fields there's no problem.

    $name =  $hook->getValue('name');


    But I also have a select field with different options that I use as tags. So the client can select more than one options in the list. (I use the jquery Select2)

    <select name="source[]" multiple="multiple">
    <option value="Google" [[!+fi.source:FormItIsSelected=`Google`]]>Google</option>
    <option value="Facebook" [[!+fi.source:FormItIsSelected=`Facebook`]]>Facebook</option>
    <option value="Twitter" [[!+fi.source:FormItIsSelected=`Twitter`]]>Twitter</option>
    </select>
    
    $source =  $hook->getValue('source');
    


    How can I get this array from this form? getValue doesn't seem to work (stays empty). Can't find any docs on it how to do this, hope somebody can help. [ed. note: sitsol last edited this post 7 years, 7 months ago.]
      • 28432
      • 372 Posts
      Hi, I've never done a posthook, but the name of your field is source[] and not source. Have you tried to change this ?
        • 43864
        • 151 Posts
        Quote from: Steeve at Sep 02, 2016, 07:17 AM
        Hi, I've never done a posthook, but the name of your field is source[] and not source. Have you tried to change this ?

        It has nothing to do with the fact that it's a prehook or posthook. I just want to get the values from the select-list. My field is source[] because it's an array (otherwise I only get the last selected option) and that's the problem with the getValue. How do I get an array with getValue?

        $source =  $hook->getValue('source'); doesn't work
        $source =  $hook->getValue('source[]'); doesn't work
        $source[] =  $hook->getValue('source[]'); doesn't work
        $source[] =  $hook->getValue('source'); doesn't work


        I think it must be done with something else than getValue, but can't find any information on it.
          • 43864
          • 151 Posts
          For the moment, because I couldn't find a solution, I did it in another way by adding the value of the option-list to a hidden field with jquery and then read that hidden field with getValue.