0

我正在尝试使用 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;
  }
}
4

1 回答 1

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“必需”验证器将首先响应,然后您的 validateForm 函数将被调用。

于 2013-03-18T11:58:34.533 回答