Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Craft 4 vs 5: different behavior when using s-action #408

Open
janhenckens opened this issue Dec 22, 2024 · 3 comments
Open

Craft 4 vs 5: different behavior when using s-action #408

janhenckens opened this issue Dec 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@janhenckens
Copy link

Bug Report

I'm updating the last of my plugins for Craft 5 and I'm seeing a strange difference in behavior.

I tried a bunch of syntaxes and different forms but to no avail - hoping you can point me in the right direction :)

My form looks like this:

<form sprig s-method="post" s-action="site/cp/save" >
    <p>
        <strong>{{ name ?? "Name not defined" }}</strong><br>
        <strong>{{ option ?? "Option not defined" }}</strong><br>
    </p>
    <div>
        <input id="name" type="text" name="name" value="{{ name ?? '' }}">
    </div>
    <div>
        <select sprig name="option" id="option">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
    </div>
    <button type="submit">Submit</button>
</form>
  • Filling out the name, skipping the select and clicking submit, I see all form fields the request my controller receives
  • But when I fill out the name, choose on option from the select field, the fields don't get submitted back to my controller, not even the select in question.

I have the same setup in my plugin and in Craft 4 this seems to work - so I'm not sure what the issue is.

Plugin Version

3.5.2

Craft CMS Version

5.57

PHP Version

8.2

@janhenckens janhenckens added the bug Something isn't working label Dec 22, 2024
@bencroker
Copy link
Collaborator

But when I fill out the name, choose on option from the select field, the fields don't get submitted back to my controller, not even the select in question.

Are you sure? Can you show me the request URL without the fields in the query string params?

@janhenckens
Copy link
Author

That might not have been the best explanation of what I'm seeing - let me try again :)

On Craft 4, the form reloads/refreshes when changing the select - but it doesn't post to my controller unless I click the submit button myself.
https://share.cleanshot.com/9K1tJsZH

But on Craft 5, the same form posts the controller straight away and then doesn't include any of the form fields
https://share.cleanshot.com/yxcYXFhW

The forms themselves and the controller are exactly the same for both versions.

@bencroker
Copy link
Collaborator

So it’s difficult to help you, seeing so little, but one thing I notice is that the 500 error appears to be the result of a POST request. Is that intentional? If you can send me some test code that I can use to replicate the issue then I’m sure I’ll be able to track it down. Right now my suspicion is that the forms are set up differently on your end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants