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

Empty inputs are not being sent via POST, or undefined if explicitly sent #33

Closed
johndwells opened this issue May 23, 2020 · 4 comments
Closed

Comments

@johndwells
Copy link
Contributor

I have a form that needs to POST an empty field value. In my context, an empty value denotes removing a coupon code from a user's cart.

However when I make a simple HTML form, and bind htmx to it, if the coupon code field is empty then it is not included in the POST request.

I have tried using hx-params="*" on the form element, but this has no effect, still only non-empty fields are POSTed.

Interestingly, when I explicitly mentioned the input field in question, e.g. hx-params="couponCode", while it did POST that form param, the value sent was undefined. I tried setting name and id attributes to couponCode but both yielded undefined...

Thanks for your help!


htmx version: 0.0.3

@1cg
Copy link
Contributor

1cg commented May 23, 2020

what sort of inputs are these?

@1cg
Copy link
Contributor

1cg commented May 23, 2020

if we can boil down a simple example I can get a test and fix in for 0.0.4 on monday

@johndwells
Copy link
Contributor Author

Here is what I used to isolate & confirm my test (uses PHP to echo the params sent):

<html>
<head>
    <script src="https://unpkg.com/htmx.org@0.0.3"></script>
    <script>htmx.logAll();</script>
</head>
<body>
<div>
    <h1>Test</h1>
    <hr>
    <div id="container">
        <h2>POSTs:</h2>
        <?php
        var_dump($_POST);
        ?>
        <hr>
        <h3>Form</h3>
        <form method="post" hx-post="/htmx.php" hx-select="#container" hx-target="#container">
            <input type="text" name="variable" value="">
            <button type="submit">Submit</button>
        </form>
    </div>
</div>
</body>
</html>

If you submit it with a value in the input, it shows up in the $_POST array; if not, then the $_POST array is empty.

Thanks for your help! :)

1cg pushed a commit that referenced this issue May 23, 2020
@1cg
Copy link
Contributor

1cg commented May 23, 2020

OK, added a regression test and fix in dev:

468c405

This will go out on monday w/ the 0.0.4 release. Thank you for catching it!

@1cg 1cg closed this as completed May 23, 2020
strangeRabbit777 added a commit to strangeRabbit777/high-power-tool that referenced this issue Aug 23, 2022
strangeRabbit777 added a commit to strangeRabbit777/high-power-tool that referenced this issue Aug 25, 2022
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

No branches or pull requests

2 participants