Skip to content

Submitting a form using GET: discrepancy between htmx and browser#3694

Open
ergor wants to merge 1 commit intobigskysoftware:devfrom
ergor:dev
Open

Submitting a form using GET: discrepancy between htmx and browser#3694
ergor wants to merge 1 commit intobigskysoftware:devfrom
ergor:dev

Conversation

@ergor
Copy link

@ergor ergor commented Mar 11, 2026

Description

Given this form:

<form action="/test" method="get">
  <input type="hidden" name="action" value="A">
  <button id="btnB" type="submit" name="action" value="B">B</button>
</form>

When clicking the button,
The browser's behavior is to append both values, resulting in a query string as "action=A&action=B".

But, when using HTMX, given this form:

<form hx-get="/test">
  <input type="hidden" name="action" value="A">
  <button id="btnB" type="submit" name="action" value="B">B</button>
</form>

When clicking the button,
HTMX issues a GET request, where the button's value overrides any other form data with the same name; the resulting query string is just "action=B". This is unexpected behavior.

This patch tries to bring HTMX in line with default browser behavior.

Now, I think this solution is rather hacky. Why is there differentiation between GET and non-GET requests in getInputValues() in the first place? I don't know the intricacies of HTMX, explanations are appreciated. I am open to iterate on this PR if the solution is below quality expectation.

Corresponding issue:
#1541
This issue brought it up, but was then closed due to #1559. However, that PR didn't fix it for the case of GET.

Testing

I tested it using the test suite. I added relevant test-cases that triggered the bug, and then verified the fix by running the tests with npm run test

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

Given this form:

  <form action="/test" method="get">
    <input type="hidden" name="action" value="A">
    <button id="btnB" type="submit" name="action" value="B">B</button>
  </form>

When clicking the button,
The browser's behavior is to _append_ both values, resulting in a query
string as "action=A&action=B".

But, when using HTMX, given this form:

  <form hx-get="/test">
    <input type="hidden" name="action" value="A">
    <button id="btnB" type="submit" name="action" value="B">B</button>
  </form>

When clicking the button,
HTMX issues a GET request, where the button's value _overrides_ any
other form data. This is _unexpected_ behavior.

This patch tries to bring HTMX in line with default browser behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant