• Resolved sethabreguer

    (@sethabreguer)


    Hello.

    When using the file upload function, is it possible to show the file / file URL in the after submission message?

    I have the form saving the file in media library, but I need to further process the URL of the uploaded file.

    Thank you in advance.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @sethabreguer

    I hope you are doing well.

    It is not possible but Forminator has some hooks that allow to modify the after submission response,

    I pinged our developers if we can find a solution for you.

    Best Regards
    Patrick Freitas

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @sethabreguer,

    Could you please try this snippet and then check whether it works fine?

    <?php
    
    add_filter( 'forminator_replace_form_data', 'wpmudev_send_uploaded_image_behavior', 10, 3 );
    function wpmudev_send_uploaded_image_behavior( $content, $data, $original_content ){
    	if ( $data['form_id'] != 2910 ) {
    		return $content;
    	}
    
    	if ( strpos( $content, '{uploaded_image}' ) !== false ) {
    		$field_name = 'upload-1';
    		if ( is_array( $data[ $field_name ] ) && ! empty( $data[ $field_name ]['file'] ) ) {
    			if ( !empty( $data[ $field_name ]['file']['file_url'] ) ) {
    				$content = str_replace( '{uploaded_image}', $data[ $field_name ]['file']['file_url'], $content );
    			}
    		}
    	}
    
    	return $content;
    }
    

    You’ll need to change 2910 in the above code to your form ID and also change upload-1 to your field’s name.

    Also, in order to show the image after the submission, you’ll need to add {uploaded_image} macro under After submission message ie under Behavior > Submission Behavior in your form.

    The above code can be added as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Best Regards

    Nithin

    Thread Starter sethabreguer

    (@sethabreguer)

    Thank you for the answer. I will try this solution and post an update if this works out.

    Thread Starter sethabreguer

    (@sethabreguer)

    I think I have a problem with inserting the macro in the inline message, because it shows up like this:

    This is how put the macro:

    Thread Starter sethabreguer

    (@sethabreguer)

    It seems that the plugin doesn’t work because I tried other macros and it works just fine. This is how I use the plugin:

    The form shortcut is [forminator_form id=”3376″] so I put the ID as 3376.

    The MU Plugin is already activated:

    This is the upload field I used:

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @sethabreguer

    I checked it and you’re right, this will not work correctly. I’m sorry about this. We are providing a lot of various custom code snippets and since they are usually created for very specific reasons, they aren’t always updated “on the fly” (as they are custom and not “official feature” of the plugin).

    This will need to be checked by our developers so I’ve already asked them to take a look and, I believe, we should be able to provide a working code for you.

    I’d appreciate some more patience though. We’ll update you here again soon with more information.

    Best regards,
    Adam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @sethabreguer,

    Please try the following new snippet and check whether it works fine:

    <?php
    
    add_filter( 'forminator_replace_form_data', 'wpmudev_send_uploaded_image_behavior', 10, 3 );
    function wpmudev_send_uploaded_image_behavior( $content, $data, $original_content ){
        $submitted_data = Forminator_CForm_Front_Action::$info['field_data_array'];
        $prepped_data = wp_list_pluck( $submitted_data, 'value', 'name' );
    	if ( $data['form_id'] != 2910 ) {
    		return $content;
    	}
    
    	if ( strpos( $content, '{uploaded_image}' ) !== false ) {
    		$field_name = 'upload-1';
    		if ( is_array( $prepped_data[ $field_name ] ) && ! empty( $prepped_data[ $field_name ]['file'] ) ) {
    			if ( !empty( $prepped_data[ $field_name ]['file']['file_url'] ) ) {
    				$content = str_replace( '{uploaded_image}', $prepped_data[ $field_name ]['file']['file_url'], $content );
    			}
    		}
    	}
    
    	return $content;
    }
    

    The steps would be similar like the previous snippet ie change?2910?in the above code to your form ID and also change?upload-1?to your field’s name.

    Also, in order to show the image after the submission, you’ll need to add?{uploaded_image}?macro under After submission message ie under Behavior > Submission Behavior in your form.

    I gave a quick test and can confirm the snippet works. Please do let us know how that goes.

    The above code can be added as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Best Regards

    Nithin

    Thread Starter sethabreguer

    (@sethabreguer)

    It works! Now the {uploaded_image} macro shows the uploaded image’s url in the after-submission image.

    Thank you very much for the help.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Show Image after Submission’ is closed to new replies.