Passing data from after_submission action to the confirmation filter in gravity forms?
I am creating a post within gform_after_submission
action, which sets a post ID variable when the post is successfully created.
https://docs.gravityforms.com/gform_after_submission/
add_action('gform_after_submission_1', [ $this, 'create_order' ], 10, 2 );
public function create_order( $entry, $form ) {
// get the current cart data array
$data = self::data();
// user id
$user_id = get_current_user_id();
// create an order array
$order = [
'post_author' = $user_id,
'post_content' = json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),
'post_type' = 'purchase-order',
'post_status' = 'publish'
];
// create order post using an array and return the post id
$result = wp_insert_post($order);
// if post id and is not a wp error then
if($result !is_wp_error($result)) {
// get the id
$post_id = $result;
// my order custom field updates go here...
}
}
Because my form is submitting via ajax, I can't invoke a header php redirect above because the redirect will just happen within the ajax request.
I need to somehow pass my $post_id
to the gravity forms gform_confirmation
filter. But I'm really struggling to see how this can be done.
https://docs.gravityforms.com/gform_confirmation/
add_filter('gform_confirmation_1', [ $this, 'order_confirmation' ], 10, 4 );
public function order_confirmation( $confirmation, $form, $entry, $ajax ) {
// update redirect to order
$confirmation = array( 'redirect' = get_permalink($post_id) );
// return confirmation
return $confirmation;
}
If anyone has any ideas that would be great thanks.
Topic plugin-gravity-forms Wordpress
Category Web