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

    I am trying to add some customg fields in the OnBeforeMailSent function.

    Here the code-examples:

    Call to eform: 
    [!eForm? &formid=`aanmeldForm` &to=`[email protected]` &tpl=`myForm` &report=`myReport` &thankyou=`myThanks` &vericode=`1` &subject=`This is the Subject` &language=`nederlands` &eFormOnBeforeMailSent=`MyOnBeforeMailSent` !]
    
    
    The function MyOnBeforeMailSent:
    
    function MyOnBeforeMailSent(&$fields) {
    	global $modx;
    	$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
    	$modx->setPlaceholder('ip',$ip);
    }
    
    The Report:
    	<h1>Hello</h1>
    	<ul>
    	  <li>... other fields from eform ...</li>
    	  <li>IP = [+ip+]</li>
    	</ul>
    	
    


    But the IP stays empty.

    Is there any way to add new placeholders which can be used in the eForm-Report?


      • 4310
      • 2,310 Posts
      Before you call eForm add the call to your snippet containing the function e.g.
      [!MySnippetContainingFunction!] 
      [!eForm? &formid=`aanmeldForm` &to=`[email protected]` &tpl=`myForm` &report=`myReport` &thankyou=`myThanks` &vericode=`1` &subject=`This is the Subject` &language=`nederlands` &eFormOnBeforeMailSent=`MyOnBeforeMailSent` !]
        • 30223
        • 1,010 Posts
        And change your function to :
        //<?php
        function MyOnBeforeMailSent(&$fields) {
        	$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
        	$fields['ip']=$ip;
                return true; //important!
        }
        


        The report template is not parsed by the modx document parser and so $modx->setPlaceholder() has no effect. eForm uses it’s own placeholder replacement function and gets the values from the $fields array.
          • 3177
          • 137 Posts
          Due to a type in the call to eForm, the function was not called.
          This is solved, but now I am getting an even stranger problem.

          I have simplified the routine as much as possible:
          (And I have left the original function names in the example, only taking out customer name and email address)

          The contents of the page:
          [[aanmeld_OnBeforeMailSent]]
          {{aanmelden}}
          


          The Call to eForm which is in a chunk called ’aanmelden’
          [!eForm? &formid=`aanmeldForm` &to=`[email protected]` &tpl=`aanmeld_Formulier` &report=`aanmeld_Report` &thankyou=`aanmeld_Thanks` &vericode=`1` &subject=`Aanmeldformulier` &language=`nederlands` &eFormOnBeforeMailSent=`xxyy`  !]
          


          The content of the snippet called ’aanmeld_OnBeforeMailSent’
          <?php
          function xxyy(&$fields) {
          	$fields['ip'] = "22";
          	return true;
          }
          
          
          if (function_exists(xxyy)) {
            print "<!-- DBG, function found. -->\n";
          } else {
            print "<!-- DBG, function NOT found -->\n";
          }
          ?>
          


          The content of chunk ’aanmeld_Report’:
          
          <ul>
          <li>Naam = [+naam+]</li>
          <li>Telefoonnummer = [+mobilenumber+]</li>
          <li>IP adres = [+ip+]</li>
          </ul>
          


          Calling the page, then filling in the two fields and klicking the Submit button gives the following error:
          Fatal error: Call to undefined function xxyy() in /home/p6900/domains/serramobile.com/public_html/assets/snippets/eform/eform.inc.php on line 378
          


          This looks like eForm cannot find the function. But I have proof that the function is there since the HTML-code show the Debug message "function found".

          Any help is appreciated.

          Thanks,

          Bert

            • 3177
            • 137 Posts
            Stop the presses, solved it.

            The snippet was called with the tag "[[".
            I changed that to "[!" and now it works.

            The examples are shown with "[[", therefore I am curious if this is a bug.
            version of MODX used: 1.0

            Thanks for your time.