Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @maxcoded,

    Trust you are doing good, and thank you for reaching out to us.

    Can you please check if the following workaround help to resolve the issue?

    add_filter( 'forminator_prepared_data', 'wpmudev_map_uplods_acf_post', 10, 2 );
    function wpmudev_map_uplods_acf_post( $prepared_data, $module_object ) {
    	if( $prepared_data['form_id'] != 1891 ){
    		return $prepared_data;
    	}
    	
    	if( isset( $prepared_data['postdata-1'] ) && is_array( $prepared_data['postdata-1'] ) ) {
    		if( isset( $prepared_data['postdata-1']['post-custom'] ) && is_array( $prepared_data['postdata-1']['post-custom'] ) ) {
    			foreach( $prepared_data['postdata-1']['post-custom'] as $post_key => $post_val ) {
    				if( strpos( $post_val['value'], '{upload' ) !== false ) {
    					$field_name = str_replace('{', '', $post_val['value'] );
    					$field_name = str_replace('}', '', $field_name );
    					if ( is_array( $prepared_data[ $field_name ] ) && isset( $prepared_data[ $field_name ]['file'] ) ) {
    						$prepared_data['postdata-1']['post-custom'][$post_key]['value'] = attachment_url_to_postid( $prepared_data[ $field_name ]['file']['file_url'] );
    					}
    				}
    			}
    		}
    	}
    	
    	return $prepared_data;
    }

    Note: Please change the form ID from 1891 to your form’s ID in the code.

    You should add the code using a mu-plugin. Please find more details on how to add a mu-plugin in our documentation here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    I hope that helps.

    Kind Regards,
    Nebu John

    Thread Starter maxcoded

    (@maxcoded)

    Hi John,

    Thank you for your prompt response. But I have just tried that and the problem still persists. The profile image is still empty even though I uploaded it during registration

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @maxcoded

    Thanks for response!

    The issue here would most likely be a bit different. The ACF field is of type “image” which is a special type and the upload field only returns a simple string which is image URL.

    If you change field type in ACF to “text” (just regular text, not WYSIWYG) it should actually map the data correctly. I’m not sure if this ACF setting will work but – that depends on how it is re-used on site – but it’s worth a check. Let us know about result, please.

    If it doesn’t work, we’ll look into it again to see how to “convert” upload field data to format used by ACF.

    Kind regards,
    Adam

    Thread Starter maxcoded

    (@maxcoded)

    Actually, the text field maps quite OK and even return the value in the frontend, the only problem i have is the image upload which doesn’t seem to return anything post-reg.

    I would like it to save to the user uploaded image once they register. If it saves to the user profile as an actual image, I can easily display the image in the frontend.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @maxcoded

    Thanks for response!

    I just re-read your initial post and I’m actually slightly confused.

    We got the “map to ACF” issue here so that’s one thing. The second thing is profile picture and that’s where my doubt is:

    by default that option does not have any option to upload image but instead takes image from Gravatar service; I understand that you created field with ACF that’s used for that but could you also explain a bit more on how this is made to show in user profile like on this picture?

    https://monosnap.com/file/3mGNrHKIPQcUBT7a6LPq46hLRu6vZ9

    I’m probably missing something simple here but it seems to be the tiny details that I need to fully understand the case. I’m sure we can fine solution then.

    Best regards,
    Adam

    Thread Starter maxcoded

    (@maxcoded)

    Thank you Adam for getting back to me, I really appreciate your time and effort.

    The thing is my aim is not trying to have a field that sets the profile picture for a user. I understand this can be simply done with Gravatar.

    However, what I’m trying to do is simply output the information a users fills while registering (using the formniator form) into some sort of Dashboard I created in the frontend. Now I’ve been successful with outputting the text fields using ACF and my Forminator form meta fields, but the issue I’m having is the image fields which doesn’t seem to output no matter what i do.

    I’m not if i fully understand what I just explained above? If not, I will do better by explaining more.

    Thanks again

    a user uploads during registration in the frontend. I’ve been able to do this for text fields using dynamic fields with Elementor Pro

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @maxcoded

    I hope you are doing well.

    Thank you for the update.

    We pinged our developers to verify why that code is not working, we will keep you posted.

    Best Regards
    Patrick Freitas

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @maxcoded

    We just got update form our developers. Please try this code:

    add_action( 'forminator_cform_user_registered', 'wpmudev_update_user_meta_acf', 10, 4 );
    function wpmudev_update_user_meta_acf( $user_id, $custom_form, $entry, $user_pass ) {
    	if( $custom_form->id != 2269 ) {
    		return;
    	}
    
    	if( $entry->meta_data['upload-1'] ) {
    		if ( is_array( $entry->meta_data['upload-1']['value'] ) && isset( $entry->meta_data['upload-1']['value']['file'] ) ) { // Check if file exists.
    			$file_url =  $entry->meta_data['upload-1']['value']['file']['file_url'];
    			$upload_id  = attachment_url_to_postid( $file_url ); // Get attachment id
    			if( $upload_id ) {
    				update_user_meta( $user_id, 'upload-1', $upload_id );
    				$mime_type = wp_get_image_mime( $file_url );
    				if( $mime_type ) {
    					$update_data = array(
    						'ID' => $upload_id,
    						'post_mime_type' => $mime_type,
    					);
    					wp_update_post( $update_data );
    				}
    			}
    		}
    	}
    }

    You can add it the same way (but instead of it, not in addition) as the one previously shared. Just make sure that the number in this line

    if( $custom_form->id != 2269 ) {

    is matching the ID of the form (it’s the same ID that you see in form’s shortcode).

    Best regards,
    Adam

    Thread Starter maxcoded

    (@maxcoded)

    HI Adam,

    You guys are amazing. THANK YOU SO MUCH

    That code snippet worked like magic, I really appreciate your help.

    THANKS AGAIN

    Please consider this ticket solved

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘File Upload With ACF and Forminator’ is closed to new replies.