• Resolved gg23

    (@gg23)


    Hi,
    Im using Forminator to create a blog post. I require that a file is uploaded. The form appears to work ie no error messages, an email is sent with all the correct details, including the uploaded file as an attachment and the file is uploaded to the media library.

    The problem is that the file uploaded cannot be accessed from the post. I would like a link in the post to the uploaded file. Is this possible?

    Thanks for your great product,
    Greg

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @gg23

    I hope you’re well today!

    The data that is/can be used in post directly, is only the data that is available through the “Post Data” field. That includes “Feature image” option (which you can enable by editing “Post Data” field on form) which will set featured image for the post but it doesn’t include any additional media upload.

    It’s possible to use such additional image (one or more) but it requires a “trick”:

    a) first, you’d need to enable “custom fields” in “Post data” field
    b) second, you would need to assign the “Upload” field of the form to a custom field there;

    Let’s say you have one upload field {upload-1}. In “post data” custom field you’d put e.g. “uploaded_image” as label and {upload-1} as value (the input box below label; you can just select your upload field by clicking on a little + icon there).

    At this point when you submit the form, the URL of uploaded image would be stored in a regular custom field, named “uploaded_image”.

    c) so you now need a way to display image form this custom field.

    If it’s fine to include that image at the bottom of the post, you could use additional code that you can add e.g. to the “functions.php” of your theme:

    add_filter( 'the_content', 'form_uploaded_image_filter' );
    function form_uploaded_image( $content ) {
    	
    	$url = get_post_meta( get_the_ID(), 'uploaded_image', true );
    	
    	
    	if ( ! empty($url) ) {
    		$content .= '<img src="' . $url . '" class="uploaded_image" />';
    	}
    	
    	return $content;
    	
    }

    Best regards,
    Adam

    Thread Starter gg23

    (@gg23)

    Hi Adam,
    Thank you very much for your prompt response. I have done all of the following:

    a) first, enabled “custom fields” in “Post data” field
    b) second, assigned the “Upload” field of the form to a custom field there {upload-1};

    As mentioned in the first message, the file (a pdf) is successfully uploaded using this mechanism but there is no link to the file in the resultant blog post.

    From what you are saying it looks as though I can access the url of the uploaded file but have to write extra code for that file link to appear in the blog post automatically.

    After submitting the form, is the URL of the uploaded pdf stored in a regular custom field? What is the name of that field? What code do I need to provide to create a link to that file in the blog post? Would the code look something like this:

    add_filter( 'the_content', 'form_uploaded_pdf_filter' );
    function form_uploaded_pdf( $content ) {
    	
    	$url = get_post_meta( get_the_ID(), 'uploaded_pdf', true );
    	
    	if ( !empty($url) ) {
    		$content .= '<a href="' . $url . '">uploaded pdf</>';
    	}
    	return $content;
    }

    Thank you`

    Thread Starter gg23

    (@gg23)

    hi Adam,
    Some progress.
    Custom field named ‘uploaded_file’
    Changed name in ‘add_filter’ to match function name

    add_filter( 'the_content', 'form_uploaded_pdf' );
    function form_uploaded_pdf( $content ) {
    	
    	$url = get_post_meta( get_the_ID(), 'uploaded_file', true );
    	
    	if ( !empty($url) ) {
    		$content .= '<a href="' . $url . '">uploaded file</>';
    	} else {
                    $content .= 'no uploaded file';
            }
    	return $content;
    }

    Getting some output so I know the function is being called. $url is not empty and just points to Array. What am I doing wrong? I have put this in “functions.php” of theme.

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @gg23

    The steps seem fine, but let me check something, are you using the regular WordPress field, not Advanced Custom Field right?

    1- Create your upload field

    https://monosnap.com/file/8LoLuzgxPgWRtv08L4GeRmCYpXON7y

    2- Add the field mapping

    https://monosnap.com/file/lBo5TaRnthsRKzR9niUpxwMSvgYaPl

    3- Confirm if mapping worked

    https://monosnap.com/file/ZmN6um9Fw2tUpdmXdHep9w6wiLDbp6

    I updated a bit your code:

    <?php
    
    add_filter( 'the_content', 'form_uploaded_pdf' );
    
    function form_uploaded_pdf( $content ) {
    
        global $post;
    	$url = get_post_meta( $post->ID, 'upload-1', true );
    
    	if ( !empty($url) ) {
    		$content .= '<a href="' . $url . '">uploaded file</>';
    	} else {
                    $content .= 'no uploaded file';
            }
    	return $content;
    }

    And now it is working well:

    https://monosnap.com/file/Qgq0CWr2HzQbu4cKwJNcs3g7WsVeCH

    Let us know if you were able to make it work now.

    Best Regards
    Patrick Freitas

    Thread Starter gg23

    (@gg23)

    Hi Patrick,
    I got it to work!!!! Not sure which of the changes did it but it works!!!

    Thank you very much for your help.

    Greg ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘File Uploaded but not appearing on post’ is closed to new replies.