We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6506
    • 35 Posts
    Hello, hope someone can help me on this as I have hit a wall now and am not sure where to go from here. I am trying to add an event listing drop down to an eform.

    After searching all the forums for how to populate a drop down list in eform I came across the following posts.

    http://modxcms.com/forums/index.php?topic=27310.0
    http://modxcms.com/forums/index.php/topic,12770.msg102365.html#msg102365

    After setting up the chunks and the snippets as set out in the posts I get the following error

    Fatal error: Call to undefined function eventListing() in C:\wamp\www\Hurst\assets\snippets\eform\eform.inc.php on line 139


    I know the select box works ok from the ditto call as when I add the chunk into the page it populates correctly, the issue only appears when trying to run the snippet call from the eform page.
    Below is all the code used which appears right as far as I can tell so I can’t understand why it can’t find the function. I hope someone can help as this is the last bit of the website to do before it goes live.

    chunks used:
    the select options in tpl eventListings

    <option value="[+description+]">[+description+]</option>


    and

    the ditto call in the select form element
      <select>
        <option value="please choose one">Please choose one</option>
     [!Ditto? &parents=`29` &tpl=`eventListings` &display=`100` &total=`100` &sortBy=`menuindex DESC` !]  </select>
    



    Snippet call:
    <?php
    function eventListing(&$fields, &$templates){
       global $modx;
       
       $ditto_params = array(
          'parents' => 29',
          'tpl' => 'eventListings',
          'display' => '100',
          'total' => '100',
          'sortBy' => 'menuindex DESC'
         
       );
     
       $templates['tpl'] = str_replace('[+eventListings+]',$modx->runsnippet('Ditto',$ditto_params),$templates['tpl']);
       
       return true;
    ?>
    


    eform call on the page
    [!eventListing!]
    <div>[!eForm? &formid=`eventsRegistration` &tpl=`eventsForm` &eFormOnBeforeFormParse=`eventListing` &debug=`0` &report=`eventsReport` &thankyou=`eventsThanks` &vericode=`1`
    &to=`[email protected]` !]</div>
    


    The call in the form:
    <div id="event" class="required">
        <label for="event">Event:</label>
    [+eventListings+]
    </div>
    


    Any help greatly appreciated. smiley
      • 36416
      • 589 Posts
      Quote from: DannyFranks at Sep 03, 2010, 03:57 AM

      Hello, hope someone can help me on this as I have hit a wall now and am not sure where to go from here. I am trying to add an event listing drop down to an eform.
      (...)
      After setting up the chunks and the snippets as set out in the posts I get the following error
      Fatal error: Call to undefined function eventListing() in C:\wamp\www\Hurst\assets\snippets\eform\eform.inc.php on line 139


      Is your snippet called "eventListing" (watch case)?
      BTW, I don’t think its good to call it exactly the same as event handler function defined inside...


      the ditto call in the select form element
        <select>
          <option value="please choose one">Please choose one</option>
       [!Ditto? &parents=`29` &tpl=`eventListings` &display=`100` &total=`100` &sortBy=`menuindex DESC` !]  </select>
      

      Ditto call inside eForm &tpl is not neccessary.


      Snippet call:
      <?php
      function eventListing(&$fields, &$templates){
        global $modx;
         $ditto_params = array(
            'parents' => 29',
            'tpl' => 'eventListings',
            'display' => '100',
            'total' => '100',
            'sortBy' => 'menuindex DESC'
         );
         $templates['tpl'] = str_replace('[+eventListings+]',$modx->runsnippet('Ditto',$ditto_params),$templates['tpl']);
         return true;
      ?>
      

      Parameter &sortBy won’t handle direction, what’s needed is &orderBy.


      eform call on the page
      [!eventListing!]
      <div>[!eForm? &formid=`eventsRegistration` &tpl=`eventsForm` &eFormOnBeforeFormParse=`eventListing` &debug=`0` &report=`eventsReport` &thankyou=`eventsThanks` &vericode=`1`
      &to=`[email protected]` !]</div>
      

      Please disable rich-text editor for snippet calling content, too...
        • 6506
        • 35 Posts
        Hi Eol, thanks for your reply. I have done as you have suggested. I now only call the ’eventListings’ tpl inside the snippet call (I have also changed the function call, best practice as you say, can get confusing otherwise)

        eventListings tpl is:

        <option value="[+description+]">[+description+]</option>
        



        Snippet call is now:

        <?php
        function eventListingDropdown(&$fields, &$templates){
           global $modx;
           
           $ditto_params = array(
              'parents' => '29',
              'tpl' => 'eventListings',
              'display' => '100',
              'total' => '100',
              'orderBy' => 'menuindex DESC'
             
           );
         
           $templates['tpl'] = str_replace('[+eventListings+]',$modx->runsnippet('Ditto',$ditto_params),$templates['tpl']);
           
           return true;
        ?>
        



        and add

         <select name="event" multiple>
        [+eventListings+]
        </select>
        


        inside my eventsForm tpl

        with the eform call on the events page

        [!eventListing!]
        [!eForm? &formid=`eventsRegistration` &tpl=`eventsForm` &eFormOnBeforeFormParse=`eventListingDropdown` &debug=`0` &report=`eventsReport` &thankyou=`eventsThanks` &vericode=`1` &to=`[email protected]` !]
        


        The only thing I am not sure on is where you have put
        please disable rich-text editor for snippet calling content, too...
        . What do you mean by this exactly and how do you do it.

        After doing all the above I still get the error message
        Fatal error: Call to undefined function eventListingDropdown() in C:\wamp\www\Hurst\assets\snippets\eform\eform.inc.php on line 139


        Hope you can help me again as I still have no idea why it shouldn’t work, and I really appreciate the quick response. Thanks again
          • 36416
          • 589 Posts
          Quote from: DannyFranks at Sep 03, 2010, 05:13 AM

          with the eform call on the events page
          [!eventListing!]
          [!eForm? &formid=`eventsRegistration` &tpl=`eventsForm` &eFormOnBeforeFormParse=`eventListingDropdown` &debug=`0` &report=`eventsReport` &thankyou=`eventsThanks` &vericode=`1` &to=`[email protected]` !]
          

          Ok, let’s reiterate what is needed (recheck names, especially case ):
          Snippets:
          [!eventListing!]
          Chunks:
          {{eventListings}}
          {{eventsForm}}
          


          Ah, and watch MODx API calls to:
          runSnippet (not runsnippet)

          The only thing I am not sure on is where you have put
          please disable rich-text editor for snippet calling content, too...
          . What do you mean by this exactly and how do you do it.

          I meant avoid rewritting eForm call by TinyMCE or other rich-text editor (so parameters stay intact: & instead of &amp;).
            • 6506
            • 35 Posts
            Hi Eol, thanks again for the quick reply but it is still no good. I have checked all names, including case, have renamed a few across the board and rechecked, turned off TinyMCE, and looked at the snippet call again but to no avail it still comes up with the same error
            Call to undefined function eventListingDropdown()
            etc. Here is my snippet code again and my eform call.

            <?php
            function eventListingDropdown (&$fields, &$templates)  {
               global $modx;
               
                  $ditto_params = array (
                  'parents' => '29',
                  'tpl' => 'eventListing',
                  'display' => '100',
                  'total' => '100',
                  'orderBy' => 'menuindex DESC'
                 
               );
             
               $templates['tpl'] = str_replace('[+eventListing+]',$modx->runSnippet('Ditto',$ditto_params),$templates['tpl']);
               
               return true;
            ?>
            


            [!eventsList!]
            [!eForm? &formid=`eventsRegistration` &tpl=`eventsForm` &eFormOnBeforeFormParse=`eventListingDropdown` &debug=`0` &report=`eventsReport` &thankyou=`eventsThanks` &vericode=`1` &to=`[email protected]` !]
            


            If you have any other suggestions will be very happy to hear them. Thanks again.

            Here is the eform configurration when I have debug on, if this sheds any light

            eForm configuration:
            
            array (
              'snipPath' => 'C:/wamp/www/Hurst/assets/snippets/eform/',
              'snipFolder' => 'eform',
              'vericode' => '1',
              'formid' => 'eventsRegistration',
              'from' => '[email protected]',
              'fromname' => 'HURST',
              'to' => '[email protected]',
              'cc' => '',
              'bcc' => '',
              'subject' => '',
              'ccsender' => '0',
              'sendirect' => '0',
              'mselector' => '0',
              'mobile' => '',
              'mobiletext' => '',
              'autosender' => '',
              'autotext' => '',
              'category' => '0',
              'keywords' => '',
              'gid' => '31',
              'noemail' => '',
              'saveform' => '1',
              'tpl' => 'eventsForm',
              'report' => 'eventsReport',
              'allowhtml' => '0',
              'replyto' => '',
              'language' => 'english',
              'thankyou' => 'eventsThanks',
              'isDebug' => '1',
              'reportAbuse' => '',
              'disclaimer' => '',
              'sendAsHtml' => '',
              'sendAsText' => '',
              'sessionVars' => '',
              'postOverides' => '0',
              'eFormOnBeforeMailSent' => '',
              'eFormOnMailSent' => '',
              'eFormOnValidate' => '',
              'eFormOnBeforeFormMerge' => '',
              'eFormOnBeforeFormParse' => 'eventListingDropdown',
              'cssStyle' => '',
              'jScript' => '',
              'submitLimit' => '0',
              'protectSubmit' => '1',
              'requiredClass' => 'required',
              'invalidClass' => 'invalid',
              'runSnippet' => '',
              'autoSenderName' => '',
              'version' => '1.4.4',
            )
            
              • 6506
              • 35 Posts
              OK solved it. The issue was with my snippet call. The rest was all fine but after following the code in this post http://modxcms.com/forums/index.php?topic=27310.0 I have now changed it to read

              <?php
              function eventListingDropdown ( &$fields, &$templates ){
                 //do all your other stuff
                  $options = ditto_GetEventList();  //Get value for $options from ditto_GetEventList function, will be used for the dropdown options list
                  $templates['tpl'] = str_replace('[+eventListing+]', $options, $templates['tpl'] );  // Set the [+eventListing+] placeholder with the options value from the ditto
                 
                  return;
              }
              
              function ditto_GetEventList()   {
                global $modx;
                 
                   $params['parents'] = '29';
                  $params['tpl'] = 'eventListing';
                  $params['display'] = 'all';
                  $params['filter'] = 'id,31,2';
                  $params['orderBy'] = 'menuindex DESC';
              
                $output = $modx->runSnippet('Ditto', $params);
                  return $output ;
              }
              ?>
              


              This has done the job. Happy Days grin grin grin
                • 36416
                • 589 Posts
                Quote from: DannyFranks at Sep 03, 2010, 08:09 AM

                Here is my snippet code again and my eform call.
                <?php
                function eventListingDropdown(&$fields, &$templates){
                 global $modx;
                  $ditto_params = array (
                   'parents' => '29',
                   'tpl' => 'eventListing',
                   'display' => '100',
                   'total' => '100',
                   'orderBy' => 'menuindex DESC'
                  );
                  $templates['tpl'] = str_replace('[+eventListing+]',$modx->runSnippet('Ditto',$ditto_params),$templates['tpl']);
                  return true;
                } // <- add function closing tag
                ?>

                If you have any other suggestions will be very happy to hear them. Thanks again.

                Heh, running out of ideas...
                What if you try to close the function definition (see the commented change above)?