PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Retrieving information from page

  1. With ajax, I was finally able to embed a form and use a popup. The old method worked (the one that was taught here on Gravity Forms). In order to pull information from the page that a visitor was inquiring on I had this code
    <a href="<?php bloginfo('url'); ?>/item-inquiry//?pagetitle=<?php the_title(); ?>&theimage=<?php my_attachment_image(0, 'medium', 'alt="' . $post->post_title . '"'); ?>&Url=<?php the_permalink() ?>" class="fancybox iframe">Email us about this item</a>
    That worked fine. Now, using ajax and having the modal hidden on the page, I do not know how to retrieve this information. I am using this

    <a class='form' href="#">Email us about this item</a></li></ul>
    
    <div id='form-popup'>
    <div id='form'>
    <?php gravity_form(2, false, false, false, '', true); ?></div></div>

    url is here, works fine http://antiquetemplates.com/demo-four/wonderful-italian-bench-fabric/

    Posted 13 years ago on Thursday January 13, 2011 | Permalink
  2. Try this:

    add_filter("gform_pre_render_9", "update_query");
    function update_query($form){
        global $post;
    
        $_GET['pagetitle'] = $post->post_title;
        $_GET['theimage'] = my_attachment_image(0, 'medium', 'alt="' . $post->post_title . '"');
        $_GET['Url'] = get_permalink($post->post_title);
    
        return $form;
    }

    Since the form is loaded on page load, but hidden from view, we can add the same parameters to the PHP $_GET/query array, without them having to be in the page URL.

    Make sure to update the "9" in "gform_pre_render_9" to the ID of your form.

    Posted 13 years ago on Thursday January 13, 2011 | Permalink
  3. I will work with this, thanks.

    Posted 13 years ago on Friday January 14, 2011 | Permalink
  4. This did retrieve the information, though it is showing on the top of the form itelf. The way I use this info is to add the information in the notification on the admin side. It is not showing there. This is what shows at the top of my form when submitting. I need to show this in the notification... What I am doing is sending an image along with information
    http://demo-four/wp-content/uploads/2010/06/71-337x450.jpg

    Posted 13 years ago on Friday January 14, 2011 | Permalink
  5. Pagetitle and Url show up and function fine, in the admin for notifications. Only "theimage" shows up on the form before and after submitting, and does not render anything in the admin. This worked fine before, so I do not think that is an issue, and of course, when you use the email form, the url for "theimage", which is what correct, shows up.

    Posted 13 years ago on Friday January 14, 2011 | Permalink
  6. I suspect the issue is that the my_attachment_image() function is "echoing" out the URL instead of just returning it. If you post the code for this function, I can show you how to return the value instead of output it.

    Posted 13 years ago on Friday January 14, 2011 | Permalink
  7. function my_attachment_image($postid=0, $size='thumbnail', $attributes='') {
    	if ($postid<1) $postid = get_the_ID();
    	if ($images = get_children(array(
    		'post_parent' => $postid,
    		'post_type' => 'attachment',
    		'order' => 'ASC',
    		'orderby' => 'menu_order ID',
    		'numberposts' => 1,//0 for all
    		'post_mime_type' => 'image',)))
    		foreach($images as $image) {
    			$attachment=wp_get_attachment_image_src($image->ID, $size);
    			?><?php echo $attachment[0]; ?><?php
    		}
    }
    Posted 13 years ago on Friday January 14, 2011 | Permalink
  8. I changed echo to return and that did it. It works now,
    <?php echo $attachment[0]; ?> to
    <?php return $attachment[0]; ?>

    Posted 13 years ago on Friday January 14, 2011 | Permalink
  9. Exactly! Kudos. :)

    Posted 13 years ago on Friday January 14, 2011 | Permalink