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

    • 25124
    • 54 Posts
    How can I get these details emailed to me in an eForm?

    <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT">

    Thanks in advance
      • 25124
      • 54 Posts
      Maybe I should elaborate. I would like to know the IP address, user agent etc of the person filling and submitting the eForm on my website so I can track them through my stats software to see how they found us, etc.
        • 25124
        • 54 Posts
        I’ve temporarily managed to get round this by generating a snippet called ipaddress which contains

        <?php
        $ip=$_SERVER[’REMOTE_ADDR’];
        echo " $ip "; ?>
        ?>

        and then calling it in the

        &subject=`Web site feedback [[ipaddress]]`

        line of the eForm setup - so that I get the IP address on the subject line.

        This is by no means ideal but gets me out of a sticky situation at the moment (e.g. I had no option but to get the site live!!) sad

        I’d still be very interested to know the ’correct’ way to do this.

        Cheers
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Ok, this got my curiosity up, and I figured it out.

          You need to use the "eformOnBeforeMailSent" event. Here’s how:
          Create a snippet, I called it "getServer":
          function getServer( &$fields ){
          	        // remote_addr
          		$fields['remote_addr']=$_SERVER['REMOTE_ADDR'];
                          $fields['remote_host']=$_SERVER['REMOTE_HOST'];
                          $fields['user_agent']=$_SERVER['HTTP_USER_AGENT'];
          		//return succes
          		return true;
          	}

          Put the snippet’s tags in your Contact document before the eForm snippet call.

          Add the function to your eForm snippet call:
          &eformOnBeforeMailSent=`getServer`
          Add the new fields to your Report chunk, just like the other input fields:
          <h3>Contact Input</h3>
          <strong>Name:</strong> [+name+]<br />
          <strong>Email:</strong> [+email+]<br />
          <strong>Message:</strong> [+message+]<br />
          <strong>IP:</strong> [+remote_addr+]<br />
          <strong>Host:</strong> [+remote_host+]<br />
          <strong>User Agent:</strong> [+user_agent+]

          And here is the result I got:
          Contact Input

          Name: Test User
          Email: [email protected]
          Message: This is a test.
          IP: 80.178.91.127
          Host:
          User Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9
          Since I’m working from a machine behind a NAT’d router via a dynamic IP, it’s not at all surprising that the REMOTE_HOST isn’t being passed.

          See the documentation at http://wiki.modxcms.com/index.php/EForm for more about the EForm events and how to make use of them.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 25124
            • 54 Posts
            That’s great - smiley smiley Thanks - all working now!!
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Added it to the Wiki HOWTO section

              http://wiki.modxcms.com/index.php/Add_stuff_to_the_eForm_Report_mailing

              Good question!
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 6726
                • 7,075 Posts
                Very cool, thanks a lot for this one !

                Now wouldn’t it be great to use this kind of logic to prevent spam (a possible Jot enhancement ?)...
                  .: COO - Commerce Guys - Community Driven Innovation :.


                  MODx est l&#39;outil id
                  • 25124
                  • 54 Posts
                  I’ve added this to my eForm call, however I also have

                  &eformOnBeforeMailSent=`getServer` &eFormOnBeforeMailSent=`eForm2db`


                  It crashes with an error if I use this twice. How can I have both these functions working?

                  Regards
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Just combine the logic of both functions into one function and call that one.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 25124
                      • 54 Posts
                      Thanks sottwell, I’ve done exactly that.

                      Works a treat now! cool