thephpleague / route

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
http://route.thephpleague.com
MIT License
651 stars 126 forks source link

I cannot make post requests #306

Closed koredalin closed 3 years ago

koredalin commented 3 years ago

Hello Philipo, I'm to use the League Route 5. I have installed XAMPP with php7.4. Whatever I do - all post requests are forbidden for me. I can handle the get requests. As I have read in internet - it should be because of CSRF security measures. I suppose - I should add a CSRF token in my view template, but the program does not go to the controller. So, the view is not rendered at all. I'm attaching some pictures of my code. I hope they will help you for faster review.

LeagueRouteComposer json LeagueRouteIndex php LeagueRouteRouteFactory php LeagueRouteRoutes php LeagueRouteMethodNotAllowedException

Please, help me with an advice.

Thank you Hristo

philipobenito commented 3 years ago

It looks to me like you’re making a GET request to a POST route

Sent from ProtonMail for iOS

On Wed, Jul 21, 2021 at 06:45, Hristo Hristov @.***> wrote:

Hello Philipo, I'm to use the League Route 5. I have installed XAMPP with php7.4. Whatever I do - all post requests are forbidden for me. I can handle the get requests. As I have read in internet - it should be because of CSRF security measures. I suppose - I should add a CSRF token in my view template, but the program cannot go to the controller. So, the view is not rendered at all. I'm attaching some pictures of my code. I hope they will help you for faster review.

LeagueRouteComposer json LeagueRouteIndex php LeagueRouteRouteFactory php LeagueRouteRoutes php LeagueRouteMethodNotAllowedException

Please, help me with an advice.

Thank you Hristo

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

koredalin commented 3 years ago

Ok - How can I change the request then? The post request is set in the html form which is not loaded. What else can I do?

philipobenito commented 3 years ago

You need a GET route/request to display the form, then you need the form to submit a POST request to a POST route that will process the form.

These can be separate controllers, or the same, that's up to you, but if you use the same it you will need to do a check to confirm what you need to do based on the incoming method, so I recommend separate controllers.

koredalin commented 3 years ago

Very helpful answer, Filipo. I'll write here where the result.

Thank you!

philipobenito commented 3 years ago

I'm going to close this as it's not an "issue" as such, more implementation advice.