首页 > 后端开发 > Golang > 正文

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

WBOY
发布: 2024-02-06 09:03:04
转载
486 人浏览过

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

问题内容

使用 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&#160;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&#160;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>
登录后复制

我动态添加了提交按钮,该按钮在这两种情况下都有效,因此我没有费心将其添加到帖子中的代码中。


正确答案


在登录和注册之间切换时,我从父 div 中删除了表单。由于某种原因,这与 htmx 属性混淆了。相反,我将表单的显示在“无”和“继承”之间切换,以保持功能完好

以上是hx-post 未使用正确的操作(路径)的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:stackoverflow.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!