PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

GF and ACF

  1. popsantiago
    Member

    Hi,
    I created a complete Custom Post Admin with http://www.advancedcustomfields.com/
    I just give some fields for a simple example :
    My collecttion CPT is composed by :
    ## Title (WP default CPT title)
    ## ACF Description name "description_collections"
    ## ACF Taxonomy Fieds name "genre_collections"
    ## ACF Gallery Fields (add-on $) name "image_collections"

    Now GF, i used :
    ## Gravity Forms + Custom Post Types add-on to put form in the CPT Collection (That's work)
    ## Article Post Title to put the Title of my CPT Collection (i use the title wp field default, so that's work)
    ## Custom Field Post (textarea) to submit my description (that's work too)
    Problems come now...
    ------
    ## For the taxonomy, i used Standard field CheckBoxes with advanced "Populate with a Taxonomy" with my custom taxonomy...
    - work for the WP taxonomy, i can see in admin edit collection the tax
    - not work for my custom ACF field because i can't set the value of the custom field with the GF checkboxen tool
    ## For the gallery, i used the Image Field of GF Article post...
    - work for the WP image, i can see all images link with this post submitted
    - not work for my custom ACF field...

    I think i can fix this problem, but not alone, because i'm really new be on php and GF custom function.

    I use the var_dump function to see what was the waiting values of the ACF fields, so :
    ## ACF taxonomy field seems waiting an array :
    get_post_meta($post->ID, 'genre_collections', true)
    ===> array(2) { [0]=> string(1) "3" [1]=> string(2) "15" }
    ===> array(2) { [0]=> string(1) "TAX_ID_1" [1]=> string(2) "TAX_ID_2" }

    ## ACF Gallerie field seems waiting an array too :
    get_post_meta($post->ID, 'image_collections', true)
    ===> array(6) { [0]=> string(2) "60" [1]=> string(2) "57" [2]=> string(2) "58" [3]=> string(2) "59" [4]=> string(2) "61" [5]=> string(2) "62" }
    ===> array(6) { [0]=> string(2) "ATTACHEMENT_POST_ID_1" [1]=> string(2) "ATTACHEMENT_POST_ID_2" [2]=> etc......

    So if i understood your documentation i need to use the http://www.gravityhelp.com/documentation/page/Gform_pre_submission to transform the GF_Fields in array and store in database ?

    Am i on the right way ? And can you help me to do the function, because i think there are some loop and count... It's hard for me to play with that...
    My head work well but not my php =)

    Thank you

    Posted 11 years ago on Monday January 28, 2013 | Permalink
  2. @popsantiago, you're doing good so far but your request is outside the support we can provide for Gravity Forms. Your customization is fairly complex and if you're new to PHP and Gravity Forms, you might want to look for assistance on our job board. Or, just keep going. I suspect you'll get it soon.

    http://www.gravityhelp.com/forums/forum/job-board

    Posted 11 years ago on Tuesday January 29, 2013 | Permalink
  3. popsantiago
    Member

    @illinoisharley, thanks for reply, i keep going before spend money.
    But can you tell me how can i retry the ATTACHEMENT_ID and where i need to do the update meta field ?
    ## Gform_pre_submission
    ## Gform_after_submission (i think here ?)

    Thank you

    Laurent

    Posted 11 years ago on Tuesday January 29, 2013 | Permalink
  4. @popsantiago: have you see this on WordPress StackExchange? Look at both answers, one might be the answer you need.

    http://wordpress.stackexchange.com/q/78826/24260

    Posted 11 years ago on Tuesday January 29, 2013 | Permalink
  5. Thanks webaware for sharing your knowledge.

    Posted 11 years ago on Wednesday January 30, 2013 | Permalink
  6. popsantiago
    Member

    Thx both,
    My first problem is fix (GF post to ACF)

    I'm working on the 2nd problems, and i'm here :

    [php]
    add_action("gform_after_submission_$formID", "acf_gallery_gformAfterSubmission", 10, 2);
    function acf_gallery_gformAfterSubmission ($entry, $form)
    {
       $post_id = $entry["post_id"];
    		$attachments = get_posts( array(
    			'post_type' => 'attachment',
    			'posts_per_page' => -1,
    			'post_parent' => $post_id
    		) );
    
    		if ( $attachments ) {
    			foreach ( $attachments as $attachment ) {
    				print_r(array($attachment->ID));
    			}
    		}
    	exit;
    }

    Now i got a string ID1ID2ID3.... but that's not good for me... i need an array like or a ID1,ID2,ID3,... (this suite help me to use the @webaware help :
    $image_collections =serialize(explode(',', $IDs));`
    and i will update ACF customfield :
    update_post_meta($post_id,'image_collections',$image_collections);

    If i'm always on the right way, can you help me with the exit format of Attachement ID ?

    Thank,

    Laurent

    Posted 11 years ago on Wednesday January 30, 2013 | Permalink
  7. popsantiago
    Member

    Oh Yeah !

    That's work, today is a little step for you, but a big one for me =)

    So for other : Function change Gravity Form image post upload to an Advanced Custom Fields add-on Gallery (maybe can help...)

    add_action("gform_after_submission_$formID", "acf_gallery_gformAfterSubmission", 10, 2);
    function acf_gallery_gformAfterSubmission ($entry, $form)
    {
       $post_id = $entry["post_id"];
    		$attachments = get_posts( array(
    			'post_type' => 'attachment',
    			'posts_per_page' => -1,
    			'post_parent' => $post_id
    		) );
    
    		if ( $attachments ) {
    			foreach ( $attachments as $attachment ) {
    				$image_collections[] = strval($attachment->ID) ;
    			}
    		}
    
    	$image_collections = serialize($image_collections);
    	update_post_meta($post_id,'image_collections',$image_collections);
    
    }

    Maybe this function can be optimized...

    See you

    Posted 11 years ago on Thursday January 31, 2013 | Permalink
  8. Thank you for sharing your progress here.

    Posted 11 years ago on Thursday January 31, 2013 | Permalink
  9. @popsantiago: well done!

    Posted 11 years ago on Friday February 1, 2013 | Permalink