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.

displaying post images in form

  1. sascha
    Member

    Is there a way to display post images in a GF form? One of my forms relates to the images of a post. I know the post ID/attachment ID, so I can call for instance wp_get_attachment_image() to display the image. Is there a way to display an image for instance in an HTML field or similar?

    Posted 12 years ago on Thursday February 9, 2012 | Permalink
  2. Hi, sascha,

    You can use the Gravity Forms hook "gform_field_input" (http://www.gravityhelp.com/documentation/page/Gform_field_input). This hook allows you to completely write the <input> tag for one of the fields on your form. In this hook, you can call the wp_get_attachment_image function with your attachment id. That function returns the full <input> tag, so you can simply return that and your new field will show.

    Below is an example I created to do this. Take a look and let me know if you have questions.

    add_action("gform_field_input", "display_attachment", 10, 5);
    function display_attachment($input, $field, $value, $lead_id, $form_id)
    {
    	//because this will fire for every form/field, only do it when it is the specific form and field
    	if ($form_id == 23 && $field["id"] == 12)
    	{
    		$input = wp_get_attachment_image(114);
    		return $input;
    	}
    }
    Posted 12 years ago on Monday February 13, 2012 | Permalink
  3. sascha
    Member

    Thanks Dana,
    that answered my other question too! I will give this a shot.

    Posted 12 years ago on Monday February 13, 2012 | Permalink
  4. @sascha Be sure to check out my response to your other post also. It provides another way to accomplish what you are trying to do using the shortcode functionality in WordPress.

    Posted 12 years ago on Monday February 13, 2012 | Permalink

This topic has been resolved and has been closed to new replies.