1

我正在使用联系表格 7,我想将联系表格数据发送到我的工作表

在代码下方获取联系表单数据

add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' ); 

function your_wpcf7_mail_sent_function( $contact_form ) {
    $title = $contact_form->title;
    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }



   if ( 'Contact form' == $title ) {

        $yourName = $posted_data['your-name'];
        $yourEmail = $posted_data['your-email'];
        $yourPhone = $posted_data['phone'];


   }
}

如何将联系表格数据发送到我的工作表?

https://www.smartsheet.com

4

1 回答 1

0

现在我已经完成了。

//smartsheet api integration with Contact Form 7
add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' ); 
function your_wpcf7_mail_sent_function( $contact_form ) {
    $title = $contact_form->title;
    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }



   if ( 'Contact form' == $title ) {

        $yourName = $posted_data['your-name'];
        $yourEmail = $posted_data['your-email'];
        $yourPhone = $posted_data['phone'];

        // Insert your Smartsheet API Token here
        $accessToken = "xxxxxxxxxxxxxxx";
        // Create Headers Array for Curl
        $headers = array(
        "Authorization: Bearer ". $accessToken,
        "Content-Type: application/json"
        );

        $postfields = '{"toTop":true, 
                           "rows":[ 
                           {"cells": [ 
                           {"columnId": xxxxxxxxxxxx, "value": "'.$yourName.'"}, 
                           {"columnId": xxxxxxxxxxxx, "value": "'.$yourEmail.'"},
                           {"columnId": xxxxxxxxxxxx, "value": "'.$yourPhone.'"} 
                           ] } 
                           ] }';
        $curlSession = curl_init("https://api.smartsheet.com/1.1/sheet/{SHEETID}/rows");
        curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curlSession, CURLOPT_POSTFIELDS,  $postfields);
        curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, "POST");
        $sheetsResponse = curl_exec($curlSession);
        if (curl_errno($curlSession)) {
        print "Oh No! Error: " . curl_error($curlSession);
        } else {
        // Assign response to variable
        $sheetObj = json_decode($sheetsResponse);
        // close curlSession
        curl_close($curlSession);
        }

        /* Put your code here to manipulate the data - simples ;) */
  }
}
于 2015-02-17T09:26:48.320 回答