• Hi there

    I’ve created a Form to let guest users to upload Photo to a new POST

    I’ve used in FORM Layout:
    File Uploader FIELD (with option “Add to Media Library” selected

    and I’ve used in FORM Processor:
    Save as Post Type
    with “Featured Image” connected to above File Uploader FIELD
    (File will be uploaded to media library and attached as featured image.)

    Everything seems to work fine,
    BUT the submitted form creates in Media Library 3 Items, all connected to the same uploaded image.

    Could you help me with this issue?

    Thank You

Viewing 11 replies - 1 through 11 (of 11 total)
  • Me too, it happens like that.
    3 same photos, but in the file is one.

    Solution:
    1. Make sure Caldera Form field for image upload is checked Add to Media Library

    2. Code edit:
    Filename: wp-content/plugins/caldera-form-metabox/includes/to-post-type.php
    around line 300, replace with this code:

    	// do upload + attach
    	if( !empty( $config['featured_image'] ) ){
    		$featured_image = Caldera_Forms::get_field_data( $config['featured_image'], $form );
    		//var_dump($featured_image);
    		$ids = array();
    		foreach( (array) $featured_image as $filename ){
    			//$featured_image_id = cf_custom_fields_attach_file( $filename, $entry_id );
    			$featured_image_id = attachment_url_to_postid( $filename );
    			update_post_meta($entry_id, '_thumbnail_id', $featured_image_id );
    			$ids[] = $featured_image_id;
    		}
    
    		if ( ! empty( $ids ) ) {
    			$ids_string = implode( ',', $ids );
    			$result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $entry_id ) );
    		}
    	}

    Around line 390, replace with this:

    		if( Caldera_Forms_Field_Util::is_file_field( $field, $form ) ){
    			//echo $field['ID'] . ' = ' . $config['featured_image'] . '<br>';
    			if( $field['ID'] == $config['featured_image'] ){
    				continue; // dont attach twice.
    			}
    			foreach( (array) $value as $file ){
    				cf_custom_fields_attach_file( $file , $entry_id );
    			}
    		}

    Comments:
    1. Media attachment has already uploaded by Caldera Form Core, so we do not need reupload using cf_custom_fields_attach_file.
    2. To attach file into post, we just need update post_parent.

    Thread Starter gabegabe

    (@gabegabe)

    Dear jinbatsu

    Thank You for sharing your solution!

    Sorry for the following newbie question…
    Is it an official solution from Caldera or is it a your temporary personal unofficial solution?

    Thank You again

    Hello @gabegabe, it is only temporary personal unofficial solution.
    So, if this plugin update, we should do manually change it again.
    Until the official fixing this issue ofcourse.

    Hello @jinbatsu,

    Thanks for posting this temporary fix – might I ask which Caldera Forms Core + Caldera Custom Fields versions this worked with? There have been a few recent updates in both in the past month and the issue still persists.

    Cheers
    -Cris

    Plugin Author Josh Pollock

    (@shelob9)

    Cris

    It’s a little tricky. The 2.1.4 update to this add-on fixed the problem but only with Caldera Forms 1.5.0.9. With Caldera Forms 1.5.0.8 or earlier, the code that fixes this issue is bypassed.

    For more information, see the update post:
    https://calderaforms.com/updates/caldera-custom-fields-2-1-4/

    Hi Josh,

    Thank you for the quick reply!

    I originally read the release notes for Caldera Custom Fields v2.1.4 and waited for the Caldera Forms 1.5.0.8 version to be released before posting. In pre-1.5.0.9 Caldera Forms versions the resultant of the Advanced Image Uploader were >3 image uploads with varying degrees of attachments.

    Once updated to v1.5.0.9/v2.1.4, I get 3 uploads (with 1 as attachment) using the Advanced Image Uploader:
    File attachments

    Additionally, the simple file upload does not seem to accept any image – it prevents form submission giving “field is required” error. I was unable to test the attachment/upload behaviour using this alternate file upload field.

    Note: I am also using the latest release of WordPress 4.7.4 and enabled a multisite network.

    Please let me know if I can provide any other relevant information.

    -Cris

    Seems I didn’t have enough coffee when I wrote the previous comment –

    I originally read the release notes for Caldera Custom Fields v2.1.4 and waited for the Caldera Forms 1.5.0.8 version to be released before posting

    should read:

    I originally read the release notes for Caldera Custom Fields v2.1.4 and waited for the Caldera Forms 1.5.0.9 version to be released before posting.

    This is still an issue with 1.5.0.10 / v2.1.4

    Have tried with and without the changes to to-post-type.php above, the result is the same as below;
    On submission of a post with images, the form just hangs, but the images are uploaded to the media library as well as a blank file with each image uploaded with no name/size/file type, but the post content itself is not being submitted.

    If I submit the post without an image, the post content/title is submitted correctly, with and without the changes to to-post-type.php above.

    Plugin Author Josh Pollock

    (@shelob9)

    In the current version if you set the file field to be uploaded to the media library and to be used as featured image it gets uploaded twice. If you don’t check add to media library in the field settings and set it it to be used as featured image, it will be uploaded once.

    Well that worked for the uploading of the image, but still the issue of the actual post content and title not working if an featured image is uploaded with the post.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘ISSUE: File will be uploaded to media library and attached as featured image.’ is closed to new replies.