Add stuff to the eForm Report mailing

From MODx Wiki

Jump to: navigation, search

Using the eformOnBeforeMailSent event

You need to add some stuff to your eForm report mailing. Let's say you want to add the user's IP address, host, and user agent.

We'll need to use the "eformOnBeforeMailSent" event, and add the fields we want to eForm's fields array.

Create a snippet, I called it "getServer", with a function:

  1. function getServer( &$fields ){
  2. // load SERVER variables into the fields array
  3. $fields['remote_addr']=$_SERVER['REMOTE_ADDR'];
  4. $fields['remote_host']=$_SERVER['REMOTE_HOST'];
  5. $fields['user_agent']=$_SERVER['HTTP_USER_AGENT'];
  6. //return success
  7. return true;
  8. }

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:

  1. <h3>Contact Input</h3>
  2.  
  3. <strong>Name:</strong> [+name+]<br />
  4. <strong>Email:</strong> [+email+]<br />
  5. <strong>Message:</strong> [+message+]<br />
  6. <strong>IP:</strong> [+remote_addr+]<br />
  7. <strong>Host:</strong> [+remote_host+]<br />
  8. <strong>User Agent:</strong> [+user_agent+]

And here is the result I got:


Contact Input

Name: Test User
Email: test@testing.com
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

Resources

Personal tools