<div class="container__form container--signup"> <form action="{{ url_for('auth.login') }}" class="form" id="form1" method="POST"> <h2 class="form__title">注册</h2> <input type="text" placeholder="用户名账号" class="input" name="username" /> <input type="email" placeholder="邮箱" class="input" name="email"/> <input type="password" placeholder="密码" class="input" name="password"/> <input type="hidden" name="register_submit" value="register_submit"> <button class="btn" type="submit" name="register_submit" onclick="submitForm()">注册</button> </form> </div> <!-- Sign In --> <div class="container__form container--signin"> <form action="{{ url_for('auth.login') }}" class="form" id="form2" method="POST"> <h2 class="form__title">登录</h2> <input type="email" placeholder="邮箱" class="input" name="email"/> <input type="password" placeholder="密码" class="input" name="password"/> <a href="#" class="link">忘记密码?</a> <input type="hidden" name="login_submit" value="login_submit"> <button class="btn" type="submit" name="login_submit" onclick="submitForm()">登录</button> </form> </div>为什么点登录仍然会提交到注册
时间: 2023-06-26 21:09:01 浏览: 126
可能是因为在登录表单中也设置了一个名为"register_submit"的隐藏输入字段,并且使用了相同的名称作为登录提交按钮的名称。这会导致在点击登录按钮时,表单将尝试提交"register_submit"的值,而不是"login_submit"的值。您可以在登录表单中更改隐藏输入字段的名称,以确保它与注册表单中的名称不同,或者在登录提交按钮中使用不同的名称。
相关问题
<div class="container__form container--signup"> <form action="{{ url_for('auth.login') }}" class="form" id="form1" method="POST"> <h2 class="form__title">注册</h2> <input type="text" placeholder="用户名账号" class="input" name="username" /> <input type="email" placeholder="邮箱" class="input" name="email"/> <input type="password" placeholder="密码" class="input" name="password"/> <button class="btn" type="submit" name="register_submit" onclick="submitForm()">注册</button> </form> </div> <!-- Sign In --> <div class="container__form container--signin"> <form action="{{ url_for('auth.login') }}" class="form" id="form2" method="POST"> <h2 class="form__title">登录</h2> <input type="email" placeholder="邮箱" class="input" name="email"/> <input type="password" placeholder="密码" class="input" name="password"/> <a href="#" class="link">忘记密码?</a> <button class="btn" type="submit" name="login_submit" onclick="submitForm()">登录</button> </form> </div>为什么提交后表单中没有“register_submit”或“login_submit”
这是因为在表单中没有设置提交按钮的值。如果您想要在提交表单时标识表单类型,可以在提交按钮上添加一个隐藏的 input 元素,并将其值设置为 "register_submit" 或 "login_submit"。例如:
```
<button class="btn" type="submit" onclick="submitForm()">注册</button>
<input type="hidden" name="register_submit" value="register_submit">
```
```
<button class="btn" type="submit" onclick="submitForm()">登录</button>
<input type="hidden" name="login_submit" value="login_submit">
```
这样,当用户提交表单时,服务器就能正确识别表单类型了。
阅读全文