Calling a php file from a form button

I am trying to call a PHP file from a form button. I put the file to be called into the asset folder of the Kirby site and calling it works well so far. However, I don’t seem to be able to call any Kirby functions from that PHP file like $kirby->url() or $kirby->option(‘someOtherSetting’);

Can Kirby functions only be used by files in the site folder? If so, can I put my PHP to be called in there as well? So far whenever I have tried that I get a server error.

Why don’t you create a route? All Kirby’s internals will be available.

I am having a bit of trouble wrapping my head around how that would work.

So my button is calling a route and the route then executes my script? (My PHP essentially calls a Python script via exec() and passes along the form input.)

So I can write my PHP in a route? Or would the route call my PHP script? And how do I pass along my form fields?

Still need to do some more studying I think.

it all depends on what you’ld like to do…

Passing form fields etc was not in the original request of “running a php script on the push of a button in panel”. Maybe what you want can be done with GitHub - bnomei/kirby3-janitor: Kirby Plugin for running commands like cleaning the cache from within the Panel, PHP code, CLI or a cronjob ?

Actually, I didn‘t say Panel. The button lives on the homepage.

Ok, here is the full description of what I want to do. I have a form field that takes a URL and a button that submits that URL. I also have a Python script that runs stuff based on that URL. I‘d like to connect that button with the Python script.

I do have a rudimentary version working by calling a PHP script that lives in /assets/php/takes_form_input.php. The PHP then calls my Python script that lives in /assets/python/does_stuff.py. But right now all the paths are hardcoded in the takes_form_input.php and I‘d like to use the dynamic paths Kirby gives me.

At least it would be nice to have. As I said, it is working right now, but hardcoded paths are not ideal.

Hi, ideally when you use forms to submit data to Kirby, you’ld want a controller (or route) to process that request.

See Controllers | Kirby CMS for more info around controllers. See above for the link to the docs for routes.

This might be useful too: Contact form | Kirby CMS (you don’t want to send an email, but run your python script)

Cheers. I‘ll look into it.

That looks exactly like what I needed. Thanks. All this controller and routes stuff is new to me. Until recently my knowledge was Kirby 2. :slight_smile:

But I will get there.