• Resolved vermit

    (@vermit)


    I am trying to allow posting blog posts from the frontend, with the ability to upload a PDF file. The problem is that the uploaded PDF is not showing in the blog post.

    My issue seems to be very similar to this other support topic, but I have not been able to get it work.

    I am using post data field and using a custom field “upload-1”
    I have also added a File Upload field with label “upload-1”.

    I have also added this snippet to show the file in the blog post:

    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 . '">upload-1</>';
    	} else {
                    $content .= 'no uploaded file';
            }
    	return $content;
    }

    Even though I have uploaded a PDF the blog post shows as “no uploaded file” in the blog post.

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter vermit

    (@vermit)

    Also want to point out that I see the uploaded file in the Forminator “Submissions” https://imgur.com/JiLrzrr
    But I don’t see the file in the individual post: https://imgur.com/gpFKXhK

    Hi @vermit

    I hope you are doing well today.

    I pinged our SLS Team to review this and see does this solution is still valid as it seems to not work on my side as well. Thank you for your patience while we look into this further.

    Kind Regards,
    Kris

    Hi again

    Please add a must-use plugin to your site’s wp-content/mu-plugins folder like this https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins, then add the following code to the plugin’s php file:

    add_action( 'forminator_post_data_field_post_saved', 'wpmudev_update_post_acf_uploads_test', 10, 4 );
    function wpmudev_update_post_acf_uploads_test( $post_id, $field, $data, $cls ){
    	$submitted_data = Forminator_CForm_Front_Action::$prepared_data;
    	$form_ids = array( 3084 ); //Please change form IDs to your form IDs
    	if ( !in_array( $submitted_data['form_id'], $form_ids ) ) {
    	  return;  
    	}
    	
    	if( isset( $submitted_data['postdata-1'] ) && is_array( $submitted_data['postdata-1'] ) ) {
    		if( isset( $submitted_data['postdata-1']['post-custom'] ) && is_array( $submitted_data['postdata-1']['post-custom'] ) ) {
    			foreach( $submitted_data['postdata-1']['post-custom'] as $post_key => $post_val ) {
    				if ( $post_val['key'] == 'upload-1' ) { //Please change test_image to your custom field name
    					if( strpos( $post_val['value'], '{upload' ) !== false ) {
    						$field_name = str_replace('{', '', $post_val['value'] );
    						$field_name = str_replace('}', '', $field_name );
    						if ( is_array( $submitted_data[ $field_name ] ) && isset( $submitted_data[ $field_name ]['file'] ) ) {
    							if ( isset( $submitted_data[ $field_name ]['file']['file_url'] ) ) {
    								$attach_url = $submitted_data[ $field_name ]['file']['file_url'];
    								if( $attach_url ) {
    									update_post_meta($post_id, $post_val['key'], $attach_url);
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    }
    
    
    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;
    }  

    This snippet will add pdf URL to upload-1 meta key of post then the following code will be able to get the PDF URL and add it at the end of the content. 3084 should be replaced with your form ID. You can find your form ID in page source where form is located, or edit your form in WP Dashboard and URL of that page edit will contain that ID.

    Kind Regards,
    Kris

    Thread Starter vermit

    (@vermit)

    Hi Kris, thanks for the response.
    I tried with the mu-plugin but it does not work. The one change I made to the code was to add “<?php” at the start. I also changed the form ID.
    I assume that the plugin was successful because I can see it under the Must Use plugins in the WordPress Plugins manager.

    Also, Is it not possible to add the code into the code snippets plugin instead of the mu-plugin?

    • This reply was modified 3 years, 3 months ago by vermit.
    • This reply was modified 3 years, 3 months ago by vermit.
    • This reply was modified 3 years, 3 months ago by vermit.
    Thread Starter vermit

    (@vermit)

    Hello?

    Can I please get some help with this?

    Thread Starter vermit

    (@vermit)

    It has been a week now and still no response?

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @vermit ,

    I’ve very sorry for the delay on our side. Can you share with us your form so we could test it?
    See here how to do that https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export

    Use pastebin.com or dropbox like a service to share the code.

    kind regards,
    Kasia

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @vermit ,
    
    We haven’t heard from you for several days now, so it looks like you no longer need our assistance.
    
    Feel free to re-open this ticket if needed.
    
    Kind regards
    Kasia

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Post data – upload PDF’ is closed to new replies.