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

    I have to set preload value for FormIt form. For that, I use hooks and it works very fine for all the fields I need, except for select fields.
    Does anybody know how to set the value of select option ?

    $hook->setValue('My_select_field','the_value_I_want_to_set');
    doesn't do the trick.
    I've also tried in vain :
    $hook->setValue('My_select_field',json_encode(array('the_value_I_want_to_set')));


    It is a simple select not a multiple select.

    Any help appreciated.
    Thanks in advance
    JCH

    This question has been answered by jchirschy. See the first response.

      • 29661
      • 116 Posts
      Are you using FormItIsSelected snippet for your options?
        --
        John
        @theboxer
        • 45206
        • 32 Posts
        Quote from: TheBoxer at May 14, 2015, 10:14 AM
        Are you using FormItIsSelected snippet for your options?

        Hi theboxher,

        Yes, I'm using FormItIsSelected in my html code like this :
        <select class="form-control" name="My_select_field" id="My_select_field">
           <option disabled="disabled" value="Néant" [[!+ficontact.My_select_field:FormItIsSelected=`none`]] selected="selected">You are</option>
           <option value="value_01" [[!+ficontact.My_select_field:FormItIsSelected=`value_01`]] >You are value 01</option>
           <option value="value_02" [[!+ficontact.My_select_field:FormItIsSelected=`value_02`]]>You are value 02</option>
        </select>


          • 45206
          • 32 Posts
          Quote from: jchirschy at May 14, 2015, 10:45 AM
          Quote from: TheBoxer at May 14, 2015, 10:14 AM
          Are you using FormItIsSelected snippet for your options?

          Hi theboxher,

          Yes, I'm using FormItIsSelected in my html code like this :
          <select class="form-control" name="My_select_field" id="My_select_field">
             <option disabled="disabled" value="Néant" [[!+ficontact.my_select_field:formitisselected="`none`]]" selected="selected">You are</option>
             <option value="value_01" [[!+ficontact.my_select_field:formitisselected="`value_01`]]">You are value 01</option>
             <option value="value_02" [[!+ficontact.my_select_field:formitisselected="`value_02`]]">You are value 02</option>
          </select>



          I don't call this snippet in the hook that preload the values.
          Should I do ?
            • 29661
            • 116 Posts
            That's not correct call. It should be:

            <select name="My_select_field">
               <option disabled="disabled" value="Néant" [[!+ficontact.My_select_field:FormItIsSelected=`none`]] selected="selected">You are</option>
               <option value="value_01" [[!+ficontact.My_select_field:FormItIsSelected=`value_01`]]>You are value 01</option>
               <option value="value_02" [[!+ficontact.My_select_field:FormItIsSelected=`value_02`]]>You are value 02</option>
            </select>
            
              --
              John
              @theboxer
            • discuss.answer
              • 45206
              • 32 Posts
              Quote from: TheBoxer at May 14, 2015, 01:04 PM
              That's not correct call. It should be:

              <select name="My_select_field">
                 <option disabled="disabled" value="Néant" [[!+ficontact.my_select_field:formitisselected="`none`]]" selected="selected">You are</option>
                 <option value="value_01" [[!+ficontact.my_select_field:formitisselected="`value_01`]]">You are value 01</option>
                 <option value="value_02" [[!+ficontact.my_select_field:formitisselected="`value_02`]]">You are value 02</option>
              </select>
              

              In fact, it is what I've done. I've made a mistake by pasting and changing some words.
              I'm using exactly what you've written.

              Actually, IT WORKS !
              Sorry, my fault.

              Since I'm using the FormItSaveForm hook, the order of the field has changed and precisely, those fields are pushed to the end of the report, even if they are placed at the top, every time they are set via $hook->setValue().
              Is there a way to reorder those type of fields ?

              Currently I'm running MODX Revolution 2.3.3-pl and FormIt 2.2.5-pl.
              Thanks for your time.
                • 29661
                • 116 Posts
                No idea about that...
                You can try filling issue in https://github.com/modxcms/formit
                  --
                  John
                  @theboxer