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

    I use the eForm, however I can’t work out how to grab the HTTP referrer and pass this onto the eForm as a field and get this sent back to us.

    <?php
      $referringPage = parse_url( $_SERVER['HTTP_REFERER'] );
      parse_str( $referringPage['query'], $queryVars );
      echo $queryVars['q']; // This is the search term used
    }
    ?>


    I’ve also found the post here, but not sure how to go forward http://modxcms.com/forums/index.php/topic,56590.0.html


    Are there any experts on how I could implement this?

    Another concern is that if they are visiting one page, then click on another, before they get to the form, how does the initial the Referrer get stored/passed?

    Thanks so much in advance for any input.

    Regards
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You should be able to use a snippet/function with one of the eform events and get that from the $_SERVER array and load it into eform’s $fields array to allow a placeholder to be used in the report tpl. Here’s a similar snippet/function I use to get the user’s IP address and browser type:
      <?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 my report tpl to use these placeholders...
      ...
      <strong>IP:</strong> [+remote_addr+]<br />
      <strong>Host:</strong> [+remote_host+]<br />
      <strong>User Agent:</strong> [+user_agent+]
      

      _SERVER["argv"] contains an array of URI arguments (i.e. the name=value pairs in the request string), while _SERVER["QUERY_STRING"] has the ?x=yx&a=bc string. However you prefer to deal with it cool
        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’ll try to integrate this and revert.

        Regards