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}

-- UPDATE 2 --


<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]

-- 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...

  • Can you enable devMode and share the full stack trace leading up that "Bad Request" error message?
    – Brad Bell
    Commented Jan 10, 2017 at 0:34
  • As requested. Edited my original question with the stack trace. Commented Jan 10, 2017 at 19:24
  • My guess is that your .htaccess file (or nginx conf file) is stripping off querystring parameters and not letting them pass through in a rewrite rule. For those setpassword requests, Craft passes code in through the querystring.
    – Brad Bell
    Commented Jan 11, 2017 at 2:02
  • I added my .htaccess file, doesn't look like anything special to me. Commented Jan 13, 2017 at 14:44
  • Move your SSL rewrite lines to above the Craft ones and see if that helps.
    – Brad Bell
    Commented Jan 13, 2017 at 22:25

1 Answer 1


Allright, after a lot of digging into my code I finally found out what went wrong.

I used this code to clear the placeholder in my input when clicking inside them:

$(".some-class input").val("");

But .some-class was the parent class of my form, which means I probably erased all values of hidden fields that Craft adds on runtime too. Fields such as <input type="hidden" name="CRAFT_CSRF_TOKEN" value=""> on which I also got an error. Still don't know about the "code param" but probably it was added somewhere later on runtime too.

After I made the selector a bit more specific, so it only selects all input elements that can be edited on the front-end, it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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