0

I have a controller which is eventually going to be set up for POSTs and GETs, but the weird thing is I can only access it through localhost/index.php?p=actions/twoFA/get where twoFA is my plugin handle and get is an action method in my controller. How can I make it so that it behaves like all the examples online where I could go to localhost/actions/twoFA/get? What's happening? Also, my actionTrigger is set to actions and I have not set up any site routes in my plugin.

UPDATE: I have decided to make this work a little differently, and I therefore do not need any help.

1
  • Went ahead and voted to close as OP stated it's no longer valid.
    – Brad Bell
    Commented Apr 4, 2018 at 22:29

1 Answer 1

1

In Craft 3 the csrf token validation in the general.php config is set to true by default. In order to request your controller with post requests you have to turn it off or include the token

https://docs.craftcms.com/v3/changes-in-craft-3.html#csrf-token-params

{% set csrfTokenName = craft.app.config.general.csrfTokenName %}         
{% set csrfToken = craft.app.request.csrfToken %}     
<input type="hidden" name="{{ csrfTokenName }}" value="{{ csrfToken }}">
2
  • this doesn't really answer my question
    – User
    Commented Apr 4, 2018 at 20:50
  • Seems like I missunderstood it. I thought it was about not being able to access it via POST request Commented Apr 4, 2018 at 21:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.