What to add in route.php for POST in Self PHP

Hello everyone, I tried to give HTTP form an action to do self PHP. But couldn;t figure it out how.
I added the POST in the route, but it results in error. So, how should I use it?
I’m quite new in using routing in the nextcloud, could anyone kindly enough to explain how to use it?

[‘name’ => ‘page#index’, ‘url’ => ‘/’, ‘verb’ => ‘GET’]
[‘name’ => ‘page#index’, ‘url’ => ‘/’, ‘verb’ => ‘POST’]
- this is the route.php

Any help would be appreciated.
Thanks in advance.

Best regards,
Travis

try using a different name (name is controller + function called). If that is not enough, youmight want to post the error you get.

I see, now I see that the ‘page#index’ means the name of the controller + function.
Thank you (again) good sir for your information. I really appreciate it :grin:

I’ve tried adding these to Route, and Controller, but I got Access forbidden
CSRF check failed

Here’s my Routes:

[‘name’ => ‘page#index’, ‘url’ => ‘/’, ‘verb’ => ‘GET’],
[‘name’ => ‘page#add’, ‘url’ => ‘/’, ‘verb’ => ‘POST’],

and PageController:

public function add() {
return new TemplateResponse(‘myApp’, ‘index’);
}

and also, here’s my index.php:

  • For the form:

echo "<form method = 'POST' action = " . $_SERVER['PHP_SELF'] .">";

  • The action:
if (isset($_POST['submit'])){
       if ($_POST['submit'] == 'Submit') {
	   
       }
}

I’m quite confused, since it seems that there’s no one in the community experienced this before.

Try going through the tutorial in the documentation:
https://docs.nextcloud.com//server/stable/developer_manual/app/tutorial.html#routes-controllers

Also note that we mostly submit via JS

Thank you for your answer, I’ve seen that tutorial. But if that’s the case, that means I couldn’t use the isset thing for self php form? cmiiw