Uniform & Airtable for long form

plugin
uniform

#1

I’m using @mzur 's wonderful Uniform plugin to create a fairly long form for people to register for an event. There’s about 16 fields, and potential for many registrants, so I’m trying to pull all submissions into a spreadsheet using something like Airtable or Google Sheets.
I’m a bit new to all this, so I’m not sure the best way to go about it.
Airtable provides a CURL API example, but I’m not sure how to translate that into using the Uniform actions.
Any help would be much appreciated!

My current code:

    if (r::is('POST')) {
        $form
        ->webhookAction([
            'url' => 'https://api.airtable.com/v0/[AIRTABLE_ID]/[SHEET]',
            'json' => true,
            'params' => [
                'method' => 'POST',
                'headers' => ['Authorization: Basic key1234567890-'],
            ],
        ]);
    }

Here’s what Airtable provides as an example:

$ curl -v -XPOST https://api.airtable.com/v0/[AIRTABLE_ID]/[SHEET] \
-H "Authorization: Bearer [APIKEYHERE]" \
-H "Content-type: application/json" \
 -d '{
  "fields": {
    "name": "John Smith",
    "cabin-type": "Interior",
    "bed-config": "King",
    "handicap": "no",
    "wheelchair": "no",
    "street-address": "123 Main St",
     ....
  }
}'

Alternatively, could I somehow show all submissions in the Kirby admin Panel?


#2

As far as I can see, internally, Uniform’s webhooks use CURL via the toolkit remote class. So all that is probably missing from your above weebhookAction is the data you want to send in the params array (not tested).


#3

Looks good so far. But you have to use your own version of the webhook action that transforms the form data in a way that is accepted by Airtable. The implementation may look like this:

<?php

namespace Uniform\Actions;

class AirtableAction extends WebhookAction
{
    protected function transformData(array $data)
    {
        return ['fields' => $data];
    }
}

Also, you have to use the Authorization: Bearer header instead of Authorization: Basic.


#4

Whoa, it worked, @mzur! Thanks so much for the quick help.
This is like magic. Great work on this plugin.

For posterity & other people searching, as long as your Airtable column titles are the same as the field names, Airtable will put the data in the correct columns.