• Resolved narhanju

    (@narhanju)


    In my index.php in WordPress, I have 5 different posts in that feed.
    Each post also contains a link/button to my contact form (which runs GravityForms).
    This is the form I am attempting to use Popupmaker for, so the user has easy access to the form for each post.

    What I would like to do is be able to pre-populate the form with the URL of the specific post it is in. This makes it so that when the user clicks that contact form (popup) for that specific post, it auto populates the URL of that post. (When clicking the form link from index, not from inside the post itself.)

    Is this possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Bel

    (@belimperial)

    Hello @narhanju

    Thanks for writing in!

    It seems you have contacted us in our support portal with the same concern. Could you please check our email and kindly let us know if using clicked trigger with Javascript helps with pre-populating the form with the URL.

    Here is also the link we suggest:

    https://gist.github.com/danieliser/e853cf76d17d14893103696574c406b2

    Hope that helps.

    Thread Starter narhanju

    (@narhanju)

    Hi @belimperial

    Thanks for the suggestion. Tried following the video. I’m directly editing my theme file btw.

    Here is the code for my link/button (with the popupmaker css class) inside index.php:

    <div class="popmake-244319" id="meta_report_icon">
    	<img src="/wp-content/uploads/report_icon.png">
    </div>

    Since I’m working with the theme file, to test, I entered the script directly into my index.php (I’m using Gravity Forms, #input_6_8 is the input field ID for my URL field):

    <script>
    
    (function ($) {
        var popupID = 244319,
            hiddenFieldSelector = '#input_6_8';
    
        $(document).on('pumBeforeOpen', '#pum-'+popupID, function () {
          var trigger = $.fn.popmake.last_open_trigger[0],
              field = $(hiddenFieldSelector);
          
          if (trigger && "" !== trigger.href) {
            field.val(trigger.href);
          }
        });
    }(jQuery));
    	
    </script>

    It doesn’t seem to be affecting my form at all. Any clues on what I’m doing wrong?

    • This reply was modified 3 years, 4 months ago by narhanju.
    • This reply was modified 3 years, 4 months ago by narhanju.
    Plugin Support mark l chaves

    (@mlchaves)

    Hey @narhanju,

    You might want to make sure your code works using Daniel’s instructions first before porting it into your theme. And, you should also follow WordPress standards for enqueueing JS.

    Here’s what I suggest:

    1) In your HTML, wrap your image with an <a href=""></> tag that has the link to your download in the href property.

    2) Make sure you add a to your click trigger CSS selector. E.g., .popmake-244319 a.

    3) Remove your script from your index.php. Add it to your functions.php or use a 3rd-party plugin (like in the video). Here’s an example of what I have working on my test site using Popup Maker, Gravity Forms, and Code Snippets following Daniel’s video.

    
    /**
     *  Add custom JavaScript for Popup Maker to the footer of your site.
     */
    function gf_download_test() { ?>
    	<script type="text/javascript">
    						
    		jQuery(document).ready(function ($) {
        		  const popupID = 662, // Popup that launches my GF form.
            	  hiddenFieldSelector = '#input_1_3'; // Hidden field ID in the GF form.
    
        		  $(document).on('pumBeforeOpen', '#pum-'+popupID, function () {
          			const trigger = $.fn.popmake.last_open_trigger[0], // Link that was clicked to launch the popup.
              		  field = $(hiddenFieldSelector);
    				
    			console.log(<code>[PUM] field:</code>);
    			console.log(field); // Sanity check.
          
          			if (trigger && "" !== trigger.href) {
    			  console.log(<code>[PUM] trigger.href: ${trigger.href}</code>); // Sanity check
            		  field.val(trigger.href);
          			} // if
        		  });
    		});
    				
    	</script><?php
    }
    add_action( 'wp_footer', 'gf_download_test', 500 );
    /** 
     * Add the code above to your child theme's functions.php file or 
     * use a code snippets plugin.
     */
    

    P.S. Please note in the code above, WordPress might substitute my string literals (backticks) in the console.logs() with <code></code>. I can post the code on GitHub if that’s better for you. Just let me know ??

    • This reply was modified 3 years, 4 months ago by mark l chaves. Reason: Note about unwanted code replacements
    • This reply was modified 3 years, 4 months ago by mark l chaves.
    • This reply was modified 3 years, 4 months ago by mark l chaves.
    Plugin Support mark l chaves

    (@mlchaves)

    Hey @narhanju,

    We’re going to close this thread since we haven’t heard back from you.

    Feel free to post a new issue or contact us directly if you need help with anything else.

    https://wppopupmaker.com/support/

    Cheers ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Prepopulate contact form field with WP post URL when it’s in a feed.’ is closed to new replies.