GithubHelp home page GithubHelp logo

wearejust-kirby-sheets's Introduction

A way to save records from Kirby3 to Google Sheets

Normally, Kirby doesn't provide a way to save data to a database. You can actually, with using the DB driver. The problem with this is that Kirby Panel doesn't provide an easy way to make this data viewable or exportable.

This package focuses on saving to an external system, namely Google Sheets.

Installation

You can install the package via composer:

composer require wearejust/kirby-sheets

Usage

You can save data to Google Sheets using the following code.

use Wearejust\KirbySheets\Connector;

$connector = new Connector();
$spreadsheetId = ID_OF_THE_GOOGLE_SPREADSHEET
$sheetName = NAME_OF_THE_TAB_IN_THE_GOOGLE_SPREADSHEET
$data = ['first_name' => 'Foo', 'last_name' => 'Bar'];

$connector->append($spreadsheetId, $sheetName, $data);

It is important that you first create a Google Secret auth file. This file is important because it sets some permissions stuff. You can create your auth file using this guide -> https://www.fillup.io/post/read-and-write-google-sheets-from-php/

In your Kirby config.php file, you can set the path to the file:

...
    'wearejust/kirby-sheets' => [
        'authentication_file' => __DIR__ . '/../../google.prod.json',
    ],
...

Usage with KirbyUniform

Most the time, you will probably use Kirby Uniform. We've created an custom action using the following code:

...
    if ($kirby->request()->is('POST')) {
        $sheetName = 'TAB X';
        $spreadsheetId = 'SPREADSHEETID_OF_GOOGLE'
        
        $form
            ->action(new SaveToGoogleSheetsAction($form, [
                'spreadsheetId' => $spreadsheetId,
                'name' => $sheetName,
                'exclude' => ['gdpr'], // You can use the exclude option to exclude keys from the form data
            ]));

        return Header::redirect('/thanks');
    }
...

License

The MIT License (MIT).

wearejust-kirby-sheets's People

Contributors

ceesvanegmond avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.