We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24100
    • 35 Posts
    Up to now I have used eForm for basic contact forms. I now need to extract a variable from a URL and pass that to a hidden field in a contact form. (The client wants to track visitors from a specific partner site.)

    Similarly, on product pages I would like to also pass a product name to the contact form from a ’contact us’ link. In this case the product name would be displayed on the contact form.

    I’ve been digging through the forum posts and have only found this post that alludes to doing this:
    http://modxcms.com/forums/index.php/topic,25050.0.html

    Any guidance or direction is greatly appreciated.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I did something similar; I use a snippet for the &eformOnBeforeMailSent event to load the submitter’s server info into the $fields array. Then I can just use the placeholders to add these to my report chunk.
      <?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;
      	}
      ?>

      So you should be able to use something like this snippet to get the GET value and add it to the report (or store it in a database or whatever you want to do with it) with no need for a hidden field.

      If you really want hidden fields, you can use similar snippets with a different event to make the placeholders available to your form chunk.
        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
        • 24100
        • 35 Posts
        Thanks for the information, Susan. I’ll be digging into this next week.