Created
January 28, 2016 17:25
-
-
Save timothyjensen/d3eae79e6c4926d1d806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Push data from Donations page to Google sheets. One form submission can populate several rows in the Google Sheet */ | |
// Make sure the trailing number (gform_after_submission_X) corresponds with the correct form number | |
add_action('gform_after_submission_1', 'add_to_google_spreadsheet_recurring', 10, 2); | |
function add_to_google_spreadsheet($entry, $form) { | |
// This is the web app URL of the Google Script running on the Google sheet | |
$post_url = "https://script.google.com/macros/s/XXXXXXXXX"; | |
// Put all the form fields (names and values) in this array | |
$gen_amt = rgar($entry, '3'); | |
$gosp_amt = rgar($entry, '19'); | |
$conferences_amt = rgar($entry, '17'); | |
//* IF A POSITIVE AMOUNT IS ENTERED FOR GENERAL FUND, THEN CREATE ARRAY AND SEND TO GOOGLE SHEETS | |
if ( $gen_amt > '$0.00'){ | |
$body_gen = array( | |
'Date' => rgar($entry, '8'), | |
'Description' => rgar($entry, '1.3') . " " . rgar($entry, '1.6') . " " . $form['fields'][1]->label, | |
'Amount' => $gen_amt, | |
'Payee' => rgar($entry, '1.3') . " " . rgar($entry, '1.6'), | |
); | |
// Send the data to Google Spreadsheet via HTTP POST request | |
$request = new WP_Http(); | |
$response = $request->post( $post_url, array( 'body' => $body_gen ) ); | |
} | |
//* IF A POSITIVE AMOUNT IS ENTERED FOR GOSPEL FUND, THEN CREATE ARRAY AND SEND TO GOOGLE SHEETS | |
if ( $gosp_amt > '$0.00'){ | |
$body_gosp = array( | |
'Date' => rgar($entry, '8'), | |
'Description' => rgar($entry, '1.3') . " " . rgar($entry, '1.6') . " " . $form['fields'][2]->label, | |
'Amount' => $gosp_amt, | |
'Payee' => rgar($entry, '1.3') . " " . rgar($entry, '1.6'), | |
); | |
// Send the data to Google Spreadsheet via HTTP POST request | |
$request = new WP_Http(); | |
$response = $request->post( $post_url, array( 'body' => $body_gosp ) ); | |
} | |
//* IF A POSITIVE AMOUNT IS ENTERED FOR CONFERENCES FUND, THEN CREATE ARRAY AND SEND TO GOOGLE SHEETS | |
if ( $conferences_amt > '$0.00'){ | |
$body_conferences = array( | |
'Date' => rgar($entry, '8'), | |
'Description' => rgar($entry, '1.3') . " " . rgar($entry, '1.6') . " " . $form['fields'][4]->label, | |
'Amount' => $conferences_amt, | |
'Payee' => rgar($entry, '1.3') . " " . rgar($entry, '1.6'), | |
); | |
// Send the data to Google Spreadsheet via HTTP POST request | |
$request = new WP_Http(); | |
$response = $request->post( $post_url, array( 'body' => $body_conferences ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment