Go语言 hx-post未使用正确的操作(路径)

mcvgt66p  于 2023-11-14  发布在  Go
关注(0)|答案(1)|浏览(106)

使用htmx提交表单和hx-post是使用当前路径的行动,而取代hx-post与行动属性,我得到正确的路径。
https://imgur.com/a/Vh3snub
这不会发送到正确的路径:

<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>

字符串
确实发送到正确的路径:

<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>


我动态地添加了提交按钮,它在两种情况下都能工作,所以我没有费心将它添加到本文的代码中。

n53p2ov0

n53p2ov01#

当在登录和注册之间切换时,我从父div中删除了表单。出于某种原因,这会扰乱htmx属性。我将表单的显示在none和inherit之间切换,以保持功能。

相关问题