简体   繁体   English

两个提交按钮具有不同的动作?

[英]Two submit buttons with different actions?

I have a form having login button and registeration button. 我有一个具有登录按钮和注册按钮的表单。

Registeration Button: 注册按钮:

This button should deal two text boxes name and email: 此按钮应该处理两个文本框名称和电子邮件:

<div id="regisbutton" class="regisbutton1">  
    <input type="submit" value="Register" class="regisbutton" name="registerSubmit"/> 
</div>

Login Button: 登录按钮:

This button should also consider only two textboxes username and password: 此按钮还应该仅考虑两个文本框的用户名和密码:

<div id="loginbutton" class="loginbuttonclass">
    <input type="submit" value="Login" class="loginbutton" name="loginSubmit" />  
</div>

Problem is I put validation JavaScript which runs automatically and before form action it checks if text boxes are empty or not. 问题是我将验证JavaScript自动运行,并且在表单操作之前检查文本框是否为空。 But I want to run this JavaScript for registeration textboxes only not for login textboxes. 但是我只想为注册文本框而不是登录文本框运行此JavaScript。

I have used submit type for both buttons. 我对两个按钮都使用了提交类型。

You are using two different actions, so you need to different forms! 您正在使用两个不同的动作,因此您需要使用不同的形式! Without the <form> tag, the input button is quite useless anyway! 如果没有<form>标记,那么输入按钮还是毫无用处! Also don't rely on javascript only, validate the form with php as well in case js is turned off by the client! 另外,不要仅依赖javascript,如果客户端关闭了js,请使用php验证表单!

So just wrap each submit button in a different form with a different action/validation and you're done! 因此,只需将每个提交按钮包装成具有不同动作/验证的不同形式,就可以完成!

如果希望仅在单击注册时才运行验证,则不应将验证功能链接到表单提交事件,而是链接到注册按钮onclick事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM