hx-post not using correct action (path)

195 views Asked by At

Using htmx to submit a form and hx-post is using the current path for the action while replacing the hx-post with the action attribute I get the correct path.

https://imgur.com/a/Vh3snub

This does not send to the correct path:

<form hx-post="/signup" class="form" id="sign-up-form" name="signupform" hx-trigger="submit" hx-encoding="multipart/form-data" hx-swap="none" hx-target="this">
                        <div class="p-4">
                            <h5>Sign Up</h5>
                            <label>Username:</label>
                            <input class="form-control" autocomplete="username" type="text" name="usernamesignup"
                                placeholder="Username" oninput="checkForValidSignUpSubmission()" required
                                id="usernamesignupinput" />
                        </div>
                        <div class="p-4">
                            <label>Email:</label>
                            <input class="form-control" type="email" name="emailsignup" autocomplete="email"
                                placeholder="[email protected]" oninput="checkForValidSignUpSubmission()" required
                                id="emailsignupinput" maxlength="64" />
                        </div>
                        <div class="p-4">
                            <label>Password:</label>
                            <input class="form-control" type="password" name="passwordsignup"
                                autocomplete="new-password" placeholder="Password"
                                oninput="checkForValidSignUpSubmission()" required id="passwordsignupinput" />
                        </div>
                        <div class="p-4">
                            <label>Confirm Password:</label>
                            <input class="form-control" type="password" autocomplete="new-password"
                                placeholder="Password" oninput="checkForValidSignUpSubmission()" required
                                id="confirmpasswordsignupinput" name="confirmpasswordsignup" />
                        </div>
                        <div class="p-4">

                            <label>Pick a profile picture</label>
                            <input id="pfpimage" type="file" accept="image/*" name="pfpformfile" required />

                        </div>
                    </form>

This does send to the correct path:

<form action="/signup" class="form" id="sign-up-form" name="signupform" hx-trigger="submit"
                        hx-encoding="multipart/form-data" hx-swap="none" hx-target="this">
                        <div class="p-4">
                            <h5>Sign Up</h5>
                            <label>Username:</label>
                            <input class="form-control" autocomplete="username" type="text" name="usernamesignup"
                                placeholder="Username" oninput="checkForValidSignUpSubmission()" required
                                id="usernamesignupinput" />
                        </div>
                        <div class="p-4">
                            <label>Email:</label>
                            <input class="form-control" type="email" name="emailsignup" autocomplete="email"
                                placeholder="[email protected]" oninput="checkForValidSignUpSubmission()" required
                                id="emailsignupinput" maxlength="64" />
                        </div>
                        <div class="p-4">
                            <label>Password:</label>
                            <input class="form-control" type="password" name="passwordsignup"
                                autocomplete="new-password" placeholder="Password"
                                oninput="checkForValidSignUpSubmission()" required id="passwordsignupinput" />
                        </div>
                        <div class="p-4">
                            <label>Confirm Password:</label>
                            <input class="form-control" type="password" autocomplete="new-password"
                                placeholder="Password" oninput="checkForValidSignUpSubmission()" required
                                id="confirmpasswordsignupinput" name="confirmpasswordsignup" />
                        </div>
                        <div class="p-4">

                            <label>Pick a profile picture</label>
                            <input id="pfpimage" type="file" accept="image/*" name="pfpformfile" required />

                        </div>
                    </form>

I am adding the submit button dynamically which works in both cases so I didn't bother adding it to the code here in the post.

1

There are 1 answers

0
Zach Anton On BEST ANSWER

I was removing the form from the parent div when toggling between login and signup. For some reason, this messes with the htmx attributes. I instead toggled my form's display between none & inherit to keep the functionality in tact