I just installed Craft fresh, there's almost nothing in my DB as I'm just beginning to develop a plugin. All I want is to save a new entry from the frontend of my website. I've done this before in other projects, but now I just can't get it to work.
I always receive the following error:
Bad Request
POST param “code” doesn’t exist.
No other errors appear, no php error log. I do not have a param or field "code" anywhere, so I don't understad where that comes from. The problem happens before the data is sent to my controller action as I never get into that action (I added a Craft::dd("Test") in the function with no results).
If I browse directly to my action controller, the function does get executed, so the path is correct. My plugin names are all correct also.
If I add CSRF token verification, I get an error that it could not be verified.
If I change the method POST to GET for testing purposes only, I get the same error but instead of paaram "code" it's param "id" that doesn't exist. I don't know what ID or CODE it's talking about.
I checked it with the working plugin I wrote for another project and I can't see any difference. I tested it localy with EasyPhP and also on an online devlopment server on Siteground, so two different environments as I thought it was maybe an issue with my local server. However, both had the same issues.
I'm at a loss, I have no idea why this will not work. Please help!
-- UPDATE --
I got this stack trace from the craft.log. Is this enough? It's talking a lot about users I see... I can't connect the dots yet...
2017/01/10 19:18:56 [error] [exception.Craft\HttpException.400] Craft\HttpException: POST param “code” doesn’t exist. in C:\gitProjects\BUT\but-project-history\craft\app\services\HttpRequestService.php:509
Stack trace:
#0 C:\gitProjects\BUT\but-project-history\craft\app\controllers\UsersController.php(333): Craft\HttpRequestService->getRequiredPost('code')
#1 C:\gitProjects\BUT\but-project-history\craft\app\framework\web\actions\CInlineAction.php(49): Craft\UsersController->actionSetPassword()
#2 C:\gitProjects\BUT\but-project-history\craft\app\framework\web\CController.php(308): CInlineAction->runWithParams(Array)
#3 C:\gitProjects\BUT\but-project-history\craft\app\framework\web\CController.php(286): CController->runAction(Object(CInlineAction))
#4 C:\gitProjects\BUT\but-project-history\craft\app\framework\web\CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#5 C:\gitProjects\BUT\but-project-history\craft\app\framework\web\CWebApplication.php(282): CController->run('setpassword')
#6 C:\gitProjects\BUT\but-project-history\craft\app\etc\web\WebApp.php(817): CWebApplication->runController('users/setpasswo...')
#7 C:\gitProjects\BUT\but-project-history\craft\app\etc\web\WebApp.php(287): Craft\WebApp->_processActionRequest()
#8 C:\gitProjects\BUT\but-project-history\craft\app\framework\base\CApplication.php(185): Craft\WebApp->processRequest()
#9 C:\gitProjects\BUT\but-project-history\craft\app\index.php(62): CApplication->run()
#10 C:\gitProjects\BUT\but-project-history\public\index.php(19): require_once('C:\\gitProjects\\...')
#11 {main}
REQUEST_URI=/
HTTP_REFERER=http://local.butprojecthistory.dev/
-- UPDATE 2 --
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
# SSL in .htaccess - Redirect to https://
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^(.*)$ https://site.com/$1 [R,L]
</IfModule>
-- UPDATE 3 --
If I add the path to my controller in the actions attribute of my form tag (but with the "actions" segment in front of the path) than I also get to the controller, if I leave it blank and use a hidden input field with an action attribute so I would get redirected to the same page, it gives the error. Does that clear something up for anybody?
-- UPDATE 4 --
Traced it back to my javascript. Started using/learning Typescript recently, so there must be something wrong with that...
.htaccess
file (or nginx conf file) is stripping off querystring parameters and not letting them pass through in a rewrite rule. For thosesetpassword
requests, Craft passescode
in through the querystring.