我正在尝试使用php中的javascript验证电子邮件和密码。 但它告诉我错误: -
{"error": "Shell form does not validate{'html_initial_name': u'initial-js_lib', 'form': <mooshell.forms.ShellForm object at 0xa50990c>, 'html_name': 'js_lib', 'label': u'Js lib', 'field': <django.forms.models.ModelChoiceField object at 0xa69d64c>, 'help_text': '', 'name': 'js_lib'}"}
我的PHP代码是
<form id="formLogin" name="formLogin" method="post" action=" " onsubmit="return validateForm()/">
<div class="divLogin">
<table>
<tr>
<td> Enter your Email: </td>
<td> <input type="text" name="txtEmail" required="required" autocomplete="off" /> </td>
</tr>
<tr>
<td> Enter your Password: </td>
<td> <input type="password" name="pwd" minlength="6" required="required" autocomplete="off" /> </td>
</tr>
</table>
</div>
<div>
<input type="submit" class="btnLogin" value="Go" style="display:inline-block; margin-left:350px; font-weight:bold; font-size:12px;" />
</div>
</form>
我的JS代码是
function validateForm(){
var checkemail=document.forms["formLogin"]["txtEmail"].value;
var atpos=checkemail.indexOf("@");
var dotpos=checkemail.lastIndexOf(".");
var checkpwd=document.forms["formLogin"]["pwd"].value;
if (checkemail==null){
document.getElementById("checkemail").innerHTML = "Please Enter Email Address";
return false;
}
if (checkpwd==null)
{
document.getElementById("checkpwd").innerHTML = "Please Enter Password";
return false;
}
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=checkemail.length)
{
alert("Not a valid e-mail address");
return false;
}
if (checkpwd==null || checkpwd=="")
{
alert("Password must be filled out");
return false;
}
}
答案 0 :(得分:0)
在您的表单标记中,您在onsubmit函数调用
后有一个额外的“/”替换下面的行
<form id="formLogin" name="formLogin" method="post" action=" " onsubmit="return validateForm()/">
与
<form id="formLogin" name="formLogin" method="post" action=" " onsubmit="return validateForm()">
还有一件事你的html5“required”验证器将首先响应,然后你的validateForm函数将被调用。