Custom field save hook

I would like to execute some php code when a custom field is saved (downloading images from an url). I guess one way would be to use the
page.update:after hook. But is there also a more elegant way of doing this inside my field’s php part?

There seems to be a save hook in the field itself. If you check out Kirby’s field definitions you’ll see how it is used.

Kirby::plugin('your/plugin', [
   'fields' => [
      'yourfield' => [
         'save' => function ($value) {
            // do whatever
            return $value;

An elegant way could also be to download the images in the panel before saving the form.

1 Like

Thanks, thats exactly what I was looking for! What would be the best way to download the images inside the in the panel, having a php script that accepts some urls via get or post and then execute the script via fetch()?

This post explains how to use field endpoints.
I think error handling will be more straight forward that way.

1 Like