将 CF7 输入值获取到另一个页面上的另一个表单

Get CF7 input values to another form on another page

我需要获取 this form diplayed on another form on another page 的值。

PS。第二种形式不是CF7。我认为 Contact Form 7 Dynamic Text Extension 不会工作。

我已经尝试过以下方法。

function save_cf7_data($cf)
{
    $submission = WPCF7_Submission::get_instance();

    // Get the post data and other post meta values.
    if ($submission) {
        session_start();
        $posted_data = $submission->get_posted_data();
        // Encode the data in a new array in JSON format
        $data = json_encode(array(
            "Property_Address" => "{$posted_data["Property_Address"]}",
            "Email" => "{$posted_data["Email"]}",
            "Phone" => "{$posted_data["Phone"]}",

        ));


        // Finally send the data to your custom endpoint
        $ch = curl_init(get_stylesheet_directory_uri() . '/second-form.php');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); //Optional timeout value
        curl_setopt($ch, CURLOPT_TIMEOUT, 5); //Optional timeout value
        $result = curl_exec($ch);
        curl_close($ch);

        return $result;
    }
    }
    add_action('wpcf7_before_send_mail', 'save_cf7_data');

问题一: 如何在 curl_init() 上传递第二种形式 URL?

问题二: 如何获取第二种形式 php 文件中的变量?

您可以在会话中保存数据:

如果会话不存在,您需要在初始化挂钩上启动会话

add_action( 'init', 'mx_session_start' );
function 'mx_session_start'() {
    if ( empty( $_SESSION ) ) {
        session_start();
    }
}

关于你在会话中保存数据的例子

$_SESSION['cf7'] = $data; //all your needed data.

使用 $_SESSION['cf7']

获取另一种形式的数据

或在您的 "another" 页面上通过操作更改简单表单上的 cf7-form