kirby-dreamform icon indicating copy to clipboard operation
kirby-dreamform copied to clipboard

Querying forms via API (Kql)

Open Matoseb opened this issue 1 year ago • 3 comments

Hello I get this error while fetching the site page using Nuxt KQL x Headless Kirby. The website has multilanguage. Is the plugin compatible with this workflow?

 ERROR  Failed KQL query "site" (...) with status code 500:
 { status: 'error',
  message:
   'Kirby\\Cms\\Page::__construct(): Argument #1 ($props) must be of type array, tobimori\\DreamForm\\Models\\FormPage given, called in /home/clients/da920ca64b0714c4f7b6fbc7005a2892/sites/mywebsite.com/site/plugins/kql/src/Kql/Interceptor.php on line 254',
  code: 500,
  key: null,
  details: [] }

Matoseb avatar Jul 24 '24 15:07 Matoseb

I always assumed it was compatible (minus the built-in snippets, of course) and the API mode was specifically to support custom forms in headless setups. I will take a look when I find time.

tobimori avatar Jul 24 '24 16:07 tobimori

I tried to query the forms page directly using KQL. But this was pointless. You may close this issue.

I always assumed it was compatible (minus the built-in snippets, of course) and the API mode was specifically to support custom forms in headless setups. I will take a look when I find time.

It is! I even query the HTMX inside my Vue/Nuxt App 😅 instead of using the API. For anyone interested:

  1. Had a few CORS isssues along the way (I had to allow all the HTMX request headers in the preflight request) in the headless.cors config.
  2. I'm rendering a dedicated php template to send the htmx:
    ...
    
      // query https://cms.kirby.example/mypage?form=page%3A%2F%2F134567
      $uuid = get('form');
      if($uuid == null) {
        throw new Exception('"form" query is required');
      }
      $uuid = urldecode($uuid);
    
      snippet('dreamform/form', [
        'form' => page($uuid),
    
    ...
    
    

Matoseb avatar Aug 17 '24 21:08 Matoseb

I just noticed that using KQL is not really possible, since models are not supported yet (I made an issue for that in the past). If you'd like to use KQL, you'd have to write a custom method that queries all fields depending on the type. Maybe I can add a toKqlArray method or something in the future, I will keep this open as a reminder to investigate it at some point...

tobimori avatar Aug 17 '24 22:08 tobimori