无法通过javascript向php提交表单

I have a form in html which I want to run verification in Javascript first before POST ing to PHP. However the link up to the PHP section does not seem to be working despite the fact that I have assigned names to each input tag and specified an action attribute in the form tag.

Here is the HTML code for the form:

<form id="signupform" action="signupform.php" method="post">
  <input type="text" name="Email" placeholder="Email Address" class="signupinput" id="email" />
  <br />
  <input type="password" name="Password" placeholder="Password" class="signupinput" id="passwordone" />
  <br />
  <input type="password" placeholder="Repeat Password" class="signupinput" id="passwordtwo" />
  <br />
  <input type="button" value="Sign Up" class="signupinput" onClick="verifypass()" id="submit" />
</form>

The button calls the javascript function which I use to verify the values of my form before sending to php:

function verifypass() {
  var form = document.getElementById("signupform");
  var email = document.getElementById("email").value;
  var password1 = document.getElementById("passwordone").value;
  var password2 = document.getElementById("passwordtwo").value;
  var emailcode = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

      if (emailcode.test(email)) {
        if (password1.length > 6) {
          if (password1 == password2) {
            form.submit(); //this statement does not execute
          } else {
            $("#passwordone").notify("Passwords do not match!", {
              position: "right"
            })
          }
        } else {
          $("#passwordone").notify("Password is too short!", {
            position: "right"
          })
        }
      } else {
        $("#email").notify("The email address you have entered is invalid.", {
          position: "right"
        })
      }
    }

我在html中有一个表单,我希望在发布到PHP之前先在Javascript中运行验证。 但是,尽管我已经为每个输入标记指定了名称并在表单标记中指定了一个action属性,但是到PHP部分的链接似乎并不起作用。 p>

这是 表单的HTML代码: p>

 &lt; form id =“signupform”action =“signupform.php”method =“post”&gt; 
&lt; input type =“  text“name =”Email“placeholder =”Email Address“class =”signupinput“id =”email“/&gt; 
&lt; br /&gt; 
&lt; input type =”password“name =”Password“占位符 =“密码”class =“signupinput”id =“passwordone”/&gt; 
&lt; br /&gt; 
&lt;输入类型=“密码”占位符=“重复密码”class =“signupinput”id =“passwordtwo  “/&gt; 
&lt; br /&gt; 
&lt; input type =”button“value =”注册“class =”signupinput“onClick =”verifypass()“id =”submit“/&gt; 
&lt  ; / form&gt; 
  code>  pre> 
 
 

该按钮调用javascript函数,用于在发送到php之前验证表单的值: p>

  function verifypass(){
 var form = document.getElementBy  Id(“signupform”); 
 var email = document.getElementById(“email”)。value; 
 var password1 = document.getElementById(“passwordone”)。value; 
 var password2 = document.getElementById(“passwordtwo”  “).value; 
 var emailcode = / ^(([^&lt;&gt;()\ [\] \\。,;:\ s @”] +(\。[^​​&lt;&gt;()\  [\] \\;:\ S @ “] +)*)|(” +“))@((\ [[0-9] {1,3} \ [0-9] {1。  ,3} \ [0-9] {1,3} \ [0-9] {1,3}])|。。(([A-ZA-Z \  -  0-9] + \)+ [  a-zA-Z] {2,}))$ /; 
 
 if(emailcode.test(email)){
 if(password1.length&gt;  6){
 if(password1 == password2){
 form.submit();  //此语句不执行
} else {
 $(“#passwordone”)。notify(“密码不匹配!”,{
位置:“右”
})
} 
}  else {
 $(“#passwordone”)。notify(“密码太短!”,{
位置:“右”
})
} 
}其他{
 $(“#email”  ).notify(“您输入的电子邮件地址无效。”,{
位置:“正确”
})
} 
} 
   code>  pre> 
  div>


 3 条回答