Help with filter to update an entry after submission

I need to implement a filter that will update a form entry after it’s been submitted. To do this, I need the filter to go pull information from a Google sheet I have set up, searching for the correct row using the Entry ID (which will already be somewhere in column A).

I wrote something to handle this, but I can’t get it to work. I’m getting the following error:

FATAL ERROR syntax error, unexpected single-quoted string “/public_html/wp-content/plugin…” on line number 10

Can anyone take a look and tell me where I may have messed this up? This is my first time working with Google APIs so some things may not yet be obvious to me that are obvious to others. I set up the API key, the OAuth consent screen, the Service Account, and I downloaded the JSON file and then uploaded it to a folder I created in the root. It appears that I don’t have the path right for the autoload.php file, but I don’t know how to fix it. When I search, I see a lot of autoload files. The one I included in the code looked to be the right one, but I’m not sure.

// Use Gravity Forms hook to capture the form submission.
add_action('gform_after_submission', 'update_gravity_form_entry_with_sheet_data', 10, 2);

function update_gravity_form_entry_with_sheet_data($entry, $form) {
    // Specify your Google Sheet ID and range (e.g., "Sheet1!A1:B10")
    $spreadsheetId = '1kB66ktI2YJviz4AD7YtGHe6kmgObQxHD_ZGzLRhGHYw';
    $range = 'Sheet1!A1:D1000000'; // Adjust the range based on your data

    // Include the Google API Client
    require_once 'public_html/wp-content/plugins/gc-google-sheets/vendor
/
autoload.php';  // Make sure this points to where your composer autoload file is.

    // Set up Google Client
    $client = new Google_Client();
    $client->setApplicationName('grantstream-gsheets-api');
    $client->setScopes([Google_Service_Sheets::SPREADSHEETS_READONLY]);
    $client->setAuthConfig('/cred/grantstream-gsheets-api-4f1ea78fd367.json');
    $client->setAccessType('offline');

    $service = new Google_Service_Sheets($client);

    // Fetch data from Google Sheets
    $response = $service->spreadsheets_values->get($spreadsheetId, $range);
    $values = $response->getValues();

    // Ensure there's data in the Google Sheet
    if (empty($values)) {
        error_log("No data found in Google Sheet.");
        return;
    }

   // Get the identifier from the Gravity Form entry
    $identifier_field_id = 275; // Adjust this to the correct field ID
    $identifier_value = rtrim($entry[$identifier_field_id]); // Trim spaces

    // Search for the matching row in Google Sheets
    $matched_row = null;
    foreach ($values as $row) {
        if (!empty($row[0]) && $row[0] == $identifier_value) { // Assuming the identifier is in column A (index 0)
            $matched_row = $row;
            break;
        }
    }

    // If no matching row is found, exit
    if (!$matched_row) {
        error_log("No matching row found in Google Sheet for identifier: " . $identifier_value);
        return;
    }

    // Extract relevant data from the matched row
    $google_data_column1 = $matched_row[1] ?? ''; // Assuming the value is in column B (index 1)
    $google_data_column2 = $matched_row[2] ?? ''; // Assuming the value is in column C (index 2)
    $google_data_column3 = $matched_row[3] ?? ''; // Assuming the value is in column C (index 3)
    // Update the Gravity Forms entry with data from Google Sheet
    $entry_id = $entry['id'];  // Get the current entry ID

    // Update the entry using Gravity Forms' GFAPI
    GFAPI::update_entry_field($entry_id, 451.3, $google_data_column1);  // Field ID 1
    GFAPI::update_entry_field($entry_id, 451.6, $google_data_column2);  // Field ID 2
     GFAPI::update_entry_field($entry_id, 452, $google_data_column3);  // Field ID 3

}

The error is coming from this part of the code, which is split over multiple lines:

    require_once 'public_html/wp-content/plugins/gc-google-sheets/vendor
/
autoload.php';  // Make sure this points to where your composer autoload file is.

Try changing it so it is all on one line:

    require_once 'public_html/wp-content/plugins/gc-google-sheets/vendor/autoload.php'; // Make sure this points to where your composer autoload file is.

Thanks. I tried that just now and it still caused a critical error on the website.

What’s the latest error?

Are you sure the file path is correct? WP does have a constant you can use to get the path for the plugins folder, e.g.

require_once WP_PLUGIN_DIR . 'gc-google-sheets/vendor/autoload.php'; // Make sure this points to where your composer autoload file is.

Hey. Thanks for continuing to look at this. I went back and realized that I had not correctly installed the library and so that path in question was NOT correct. I went back, installed everything, and corrected the path. However, it still did not work and I discovered that it was causing conflicts in other parts of my site. I disabled the snippet and uninstalled all the API stuff and now the site is back up and functioning, but I still haven’t solved my original problem. I think I’m going to have Gravity Experts take a look at it.