将自定义数据发送到自定义确认对象 - Gravity Forms

目前,我通过使用类似的代码结构发布到第 3 方,进一步增强了重力形式的功能:


add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );

function post_to_third_party( $entry, $form ) {


    $endpoint_url = 'https://thirdparty.com';

    $body = array(

        'first_name' => rgar( $entry, '1.3' ),

        'last_name' => rgar( $entry, '1.6' ),

        'message' => rgar( $entry, '3' ),

        );

    GFCommon::log_debug( 'gform_after_submission: body => ' . print_r( $body, true ) );


    $response = wp_remote_post( $endpoint_url, array( 'body' => $body ) );

    GFCommon::log_debug( 'gform_after_submission: response => ' . print_r( $response, true ) );

}

我知道您可以注入各种挂钩点,但我在自定义确认方面遇到了问题。我能够创建过滤器并进行自定义确认,但我希望它是动态的。


当我将数据发送给第 3 方时,在过滤器操作结束之前将响应发送回,我想将该数据传递给 custom_confirmation 挂钩。我怎样才能做到这一点?有没有办法操纵从 after_form_submission 钩子传递的 $form 或 $entry 变量?


add_filter( 'gform_confirmation', 'custom_confirmation', 10, 4 );

function custom_confirmation( $confirmation, $form, $entry, $ajax ) {

    if( $form['id'] == '101' && $form['success'] == 1 ) {

        $confirmation = array( 'redirect' => 'http://www.google.com' );

    } elseif( $form['id'] == '101' && $form['success'] == 0) {

        $confirmation = "failed";

    }

    return $confirmation;

}

像我上面发布的那样可能吗?


达令说
浏览 149回答 1
1回答

拉丁的传说

我不得不通过在 after_submission 挂钩底部回显一个脚本来执行一个非常丑陋的解决方法,该脚本将确认消息保存到变量中。然后将该变量传递到浏览器的 localSession。然后在加载页面并将消息显示给用户时获取它。if (is_numeric($RESPONSE_VAR)) {&nbsp; &nbsp; $msg = "<h2>Your registration was successful</h2><br><h2>Thanks for contacting us! Check your email, and activate your account..</h2>";&nbsp; &nbsp; echo "<script>localSession.removeItem('confirmation'); localStorage.setItem('confirmation', '$msg');</script>";}else{&nbsp; &nbsp; $msg = "<h2>Sorry something went wrong with your application, please try again. <a href='https://URL/FORM_NAME/'>Go Back</a></h2>";&nbsp; &nbsp; echo "<script>localSession.removeItem('confirmation'); localStorage.setItem('confirmation', '$msg');</script>";}
打开App,查看更多内容
随时随地看视频慕课网APP