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

    I would like to have a record of user data on the eForms (referrer, country, IP etc) as well as pass this information into the database. I know there is an extension for eForms to pass into the database, however does anyone know how to get the environmental variables onto the received email too?

    Thanks
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I use a snippet like this...
      <?php
      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;
      	}
      ?>

      and added this to my eForm snippet call...
      &eformOnBeforeMailSent=`getServer`

      As far as the country, your snippet would also need to access an IP address location service using the remote address value.

      The extra $fields values can be added to your report chunk like the form field placeholders...
      <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+]
        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
        • 26951
        • 41 Posts
        Wonderful, thanks.

        Do you pass these into the database too?

        Sorry let me expand on that a bit:

        Suing eFormtodb you would place

        &eFormOnBeforeMailSent=`eForm2db`

        I am wondering if &eformOnBeforeMailSent=`getServer, eForm2db` would work, passing through the EV to the DB?

          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It would probably be easier to just use the eform2db snippet and add a few lines to the beginning of it to add your SERVER values.
            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