提交时检查密码

发布于 2024-12-17 07:57:28 字数 1078 浏览 3 评论 0原文

我有一个基本的注册表单:

<form action="adduser" method="post" onsubmit='passwordCheck()'>
    Email Address: <input type="email" name="email" required autocomplete="on" placeholder="[email protected]"/><br/>
    Username: <input type="text" name="username" maxlength=25 required placeholder="JoyfulSophia"/><br/>
    Password: <input type="password" name="password" id='password' onkeydown='checkPassword()' maxlength=30 required placeholder="**********" />
    Password (Again): <input type='password' id='pass_repeat'/>
    <br/>
    <br/>
    <input type="submit" value="Send" /> <input type="reset">
</form>

因此,当提交表单时,它会调用passwordCheck(),它会根据容易猜到的密码对其进行测试,不重复相同的密码等。它将错误(如果有)放入 < p>(未显示)。 checkPassword() 有效并且错误显示正确,但表单仍然提交,而我读过的 JS 文档说如果 onsubmit 返回 false,则表单不应提交。

为什么 checkPassword() 返回 false 时表单正在提交?此外,密码输入中的每次击键都不会调用 checkPassword()。

I have a basic signup form:

<form action="adduser" method="post" onsubmit='passwordCheck()'>
    Email Address: <input type="email" name="email" required autocomplete="on" placeholder="[email protected]"/><br/>
    Username: <input type="text" name="username" maxlength=25 required placeholder="JoyfulSophia"/><br/>
    Password: <input type="password" name="password" id='password' onkeydown='checkPassword()' maxlength=30 required placeholder="**********" />
    Password (Again): <input type='password' id='pass_repeat'/>
    <br/>
    <br/>
    <input type="submit" value="Send" /> <input type="reset">
</form>

So when the form is submitted, it calls passwordCheck(), which tests it against easily guessable passwords, not repeating the same password etc. It puts the error, if any, in a <p> (not shown). checkPassword() works and the error is displaying correctly, but the form still submits while JS docs that I've read say that if onsubmit returns false, the form should not submit.

Why is the form submitting when checkPassword() returns false? Also, checkPassword() is not being called on each keystroke in the passwords input.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月朦胧 2024-12-24 07:57:28

需要

<form ... onsubmit="return passwordCheck();">

对于 onkeydown, 检查您的 checkPassword() 函数是否确实被调用。让它做一个alert()或类似的事情。

It needs to be

<form ... onsubmit="return passwordCheck();">

as for the onkeydown, check that your checkPassword() function is actually being called. have it do an alert() or something similar.

看春风乍起 2024-12-24 07:57:28

添加退货

onsubmit='return passwordCheck()'

Add return

onsubmit='return passwordCheck()'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文