putyourlightson / craft-sprig

A reactive Twig component framework for Craft CMS.
https://putyourlightson.com/plugins/sprig
MIT License
129 stars 9 forks source link

`Request missing required param` when setting a new password with Sprig #348

Closed shifuma closed 9 months ago

shifuma commented 10 months ago

Following other Sprig forms I've built and Ryan's video, I have a user registration flow and set password form with Sprig that has recently stopped working.

<form sprig s-method="post" s-action="users/set-password">
  {{ csrfInput() }}
  {{ hiddenInput('code', code) }}
  {{ hiddenInput('id', id) }}
  <label for="newPassword">New Password</label>
  <input id="newPassword" name="newPassword" type="password">
  <button type="submit">Save</button>
</form>

With this I get a couple of errors:

[web.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Undefined array key "message" in /var/www/html/vendor/putyourlightson/craft-sprig-core/src/controllers/ComponentsController.php:165
[web.ERROR] [yii\web\HttpException:400] yii\web\BadRequestHttpException: Request missing required param in /var/www/html/vendor/craftcms/cms/src/web/Request.php:1081
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/controllers/UsersController.php(2468): craft\web\Request->getRequiredParam('id')

I tried inlining the values like this <form sprig s-method="post" s-action="users/set-password" s-val:code="{{ code }}" s-val:id="{{ id }}"> but there was no difference in behaviour.

I was able to reproduce on a fresh Craft 4.6.1 and Sprig 2.7.3 install. But I'm not convinced this is a Sprig thing since it's just hitting the users/set-password controller?

bencroker commented 10 months ago

That second error indicates that no id parameter value was submitted. Can you double check that you are indeed setting the value of id before the form is output, and that it is non-empty?

shifuma commented 10 months ago

Yeah, I confirmed that it is set properly: <input type="hidden" name="id" value="8ff325bd-31....">

bencroker commented 10 months ago

I tracked this down to a bug which I'll fix for the next release. Sprig has special handling for the set password action and something must have changed in Craft since 4.0.0 to trigger this issue. Thanks for reporting!

shifuma commented 10 months ago

Great to hear, thanks Ben!

bencroker commented 9 months ago

Fixed in https://github.com/putyourlightson/craft-sprig-core/commit/1b0bb173dca2281889ff934dd07b88803801b1c4 for the next release.