Making calculations on ACF fields after form submission

Hey all,

I’m attempting to use Gravity Forms and Advanced Post Creation to accomplish a relatively simple task, but I can’t seem to get it to work. Wondering if anyone can point me in the right direction?

Basically, I have a ACF number field in an options page called books_global. Then I have a form with a number field called books_single. When a user fills out the form, a new post is created and the content of the post should be a calculation of the books_global field and the books_single field. (I know, it’s an odd setup, but the client wants this updated number to be in an RSS feed, so I figured it would be easy enough to accomplish with posts.)

So global_books should always be a iterating whatever folks enter into the number field in the form.

I have the post creation part set up, but I not able to hook into the form submission to grab books_global and do my calculation. This is what I have now:

add_action( 'gform_advancedpostcreation_post_after_creation_1', function ( $post_id, $feed, $entry, $form ){
	$books_single = $entry['1']; // the number field from the form
	$books_global = get_field('books_global', 'options'); // the global field
	$combined_books = $books_single + $books_global; // the calculation
	update_field( 'books_global', $combined_books, 'options'); // update the ACF field on the options page
}

Can anyone point me in the right direction here? Any help would be appreciated!

Hi There,

You’re using get_field and update_field which are ACF specific functions. We can’t really help you with those. I don’t see anything incorrect with your function, but you would need to add some logging to see if you’re getting values in those areas where you’re pulling values (from the Entry, from the Option, from your calculation and when you write it.

You can add Custom Logging statements that will be sent to our Gravity Forms Logging, using the details in this document:

I hope that’s helpful. You mostly want to make sure you’re actually getting values and then troubleshoot from there.