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

    does anybody know how I can retrieve TV option value from eform.
    I’d like ti use tv options values as <option> for a <select> in eform tpl.

    Is #FUNCTION the way to go?

    Thx for your help.

    :-)
      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 30223
      • 1,010 Posts
      #FUNCTION is only for validating posted values...

      Supposing the output of the TV is a delimited list you could use a function similar to this in the eFormOnBeforeFormParse event:
      <?php
      function onBeforeParseFunction( &$fields, &$templates){
           global $modx;
          $replaceVar = '';
          //retrieve TV values into an array 
          $list = explode(',',$modx->getTemplateVarOutput('yourTVname'));
          foreach($list as $name){
              $replaceVar .= '<option value="'.$name.'">'.$name.'<option>';
          }
          //replace placeholder in form template
          $templates['tpl'] = str_replace('[+optionPlaceHolder+]',$replaceVar,$templates['tpl']);
          //exit event
          return true
      }
      ?>
      


      Your form template would have to contain something like this:
      <form action="[~[(id)]~]" id="myForm" name="myForm" method="post">
      <select id="selectField" eform="Select Box::1::">
      	<option value="" selected="selected"></option>
      	[+optionPlaceHolder+]
      </select>
      <!-- Rest of form -->
      </form>
      


      See the eForm documentation and examples for calling events...
        • 11975
        • 2,542 Posts
        Thanks for the clue and the sample code.

        :-)
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 27376
          • 576 Posts
          Quote from: TobyL at Jan 07, 2007, 02:40 PM
          Supposing the output of the TV is a delimited list you could use a function similar to this in the eFormOnBeforeFormParse event:
          That is also something I’ve been looking for. Thanks!
            • 34162
            • 1 Posts
            Me too, thx.

            two questions:
            - I suppose this function must be added as a plugin + linked/checked to the event in the Events tab?
            - can this technique also be used for the Makeform snippet since I want my values added to the DB?

              • 11975
              • 2,542 Posts
              I can’t answer the first one but about makeForm it’s a class and not a snippet.
              You can use makeForm to accelerate your snippet development but you’ll have to code.
              :-)
                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 30223
                • 1,010 Posts
                Quote from: BB at Jan 10, 2007, 01:50 PM

                - I suppose this function must be added as a plugin + linked/checked to the event in the Events tab?

                Nope,.. events in eForm are not the same as events in the MODx framework. You add the function by placing it in a new snippet and call that snippet in the same page(s) you use eForm.
                [[snippetWithEformFunctions]]
                [!eForm? &eFormOnBeforeFormParse=`eventFunctionName` .... !]
                


                Have a look through the events example in the eform documentation (assets/eform/docs/eform.htm)
                  • 34162
                  • 1 Posts
                  thx!