jQuery验证完成后,将省略表单发布 [英] form post is omitted after jquery validation is completed

查看:80
本文介绍了jQuery验证完成后,将省略表单发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在添加验证之前,表单已正确发布.

Before I add validation, the form is posting correctly.

收到此表单,该表单将验证电子邮件,完成后,表单将完成onsubmit javascript函数,但表单数据不会发布?为什么?

Got this form, which validates the email and after it is done the form completes the onsubmit javascript function but the data of the form is not posted? Why?

我也尝试使用该操作,但是在验证表单之后,就不再使用该操作.

Also I tried to use the action but after the form is validated the action is never used.

这是表格:

<form  id="signup_form" name="signup_form"  method="post" onsubmit="loadPage('registration')">  
<!--action="/registration" method="post"--> 
  <h2>E-MAIL ADDRESS<sup><b>*</b></sup></h2>
  <input value="<?=$uEmail?>" type="text" name="signup_email" id="signup_email" size="40" class="" style="margin-right:6px;font-size:18px" /><br /><label for="signup_email">Example: me@mydomain.com</label>
  <br class="clear" /><br />
  <h2>PASSWORD<sup><b>*</b></sup></h2>
  <input type="password" name="requiredpWord" id="requiredpWord"  size="15" style="width:120px" ><br />
  <h2>CONFIRM PASSWORD<sup><b>*</b></sup></h2>
  <input type="password" name="requiredcpWord" id="requiredcpWord"  size="15" style="width:120px" ><br />
  <button id="submitBTN" type="submit" value="COMPLETE SIGNUP">COMPLETE SIGN UP</button>
</form>

该操作已被注释掉,我尝试使用该操作来替换onsubit,但是当我执行该操作时,按下按钮却没有任何作用.

The action is commented out and I tried using that to replace the onsubit but when I do the action of pressing the button does nothing.

这里是有效的JQuery验证表单.我添加了SubmitHandler,以查看该表单是否包含该帖子.到目前为止,它什么也没做.

Here is the form JQuery validation, which works. I added the submitHandler to see if the form would include the post. it did nothing as of now.

$(function() {
    $("#signup_form").validate({
        rules: {
            signup_email: {
                email: true,
                required: true,
                remote: { 
                    type: 'post',
                    url: 'registration/isEmailAvailable',
                    data: {
                        email:
                            function() {
                                 // console.log(data);
                                return $( "#signup_email" ).val();
                            }
                    }
                }
            },
            requiredpWord: {
                required: true,
                minlength: 8
            },
            requiredcpWord: {
                equalTo: "#requiredpWord"
            }
        },
       messages: {
          signup_email: {
            required: "Please provide an email",
            email: "Please enter a valid email address"//,
           },
          requiredpWord: {
            required: "Please provide a password.",
            minlength: "Your password must be at least 8 characters long"
           },
          requiredcpWord: "Your passwords do not match."
      },
    invalidHandler: function(form, validator) {
       var errors = validator.numberOfInvalids();
       if (errors) {
          var message = errors == 1
          ? 'Please correct the following error:\n'
          : 'Please correct the following ' + errors + ' errors.\n';
          var errors = "";
          if (validator.errorList.length > 0) {
           for (x=0;x<validator.errorList.length;x++) {
               errors += "\n\u25CF " + validator.errorList[x].message;
           }
        }
       alert(message + errors);
      }
      validator.focusInvalid();
     },
      //added this to see if the form would post, did not change it
       submitHandler: 
         function(form) {
              // do other things for a valid form
              form.submit();
           }
});

php代码很简单...

the php code is simple...

var_dump($_POST);
var_dump($_GET);

POST 返回一个空数组.根本没有表格数据.

The POST returns an empty array. No form data at all.

GET 返回注册"

loadPage("registration")函数只是以下内容:

function loadPage(name){    
    window.location.replace('/'+name);

}

所以我要重申我的问题:

So to reiterate my questions:

  1. 为什么POST中缺少表单数据?

  1. Why is the form data missing from the POST?

奖金::为什么在表单验证操作后什么都不做,但是onsubmit有效?请注意,如果我将submitHandler从JQuery验证中排除,这将成立.

BONUS: Why after the form validates the action does nothing, but onsubmit works? Note this holds true if I exclude the submitHandler from the JQuery validation.

更新:测试表单验证,确认表单正确或正确.

Update: Test for Form validation, form is validating as true or false correctly.

$( "#submitBTN" ).click(function() {
  alert( "Valid: " + $("#signup_form").valid() );
});

更新:

  1. 添加了invalidHandler代码,表单正确验证,仅在出现错误时显示.这不是验证问题.
  2. 已删除onsubmit以执行操作,现在验证不执行任何操作.使用jQuery验证插件1.7.我将检查是否有较新的版本.上面的注意代码仍显示为onsubmit,因为我不想更改整个问题.
  3. submitHandler也未注释.没有显示警报.
  1. Added invalidHandler code, form validates correctly, displays only if there is an error. This is not a validation issue.
  2. Removed onsubmit for action, now validation does nothing. Using jQuery validation plug-in 1.7. I'm going to check for a newer release. NOTE code above still displays onsubmit because i don't want to change the whole problem.
  3. submitHandler is also uncommented. The alert is not being displayed.

更新4 问题存在于用于电子邮件验证的远程帖子中.如果我注释掉远程验证,则该帖子实际上已完成.根据这一发现提出了一个新问题.

UPDATE 4 Issue resides with remote post for email validation. If i comment out the remote verification the post actually completes. Opened a new question based upon this finding.

推荐答案

删除onsubmit="loadPage('registration')"并取消注释submitHandler部分应该可以完成此工作. 还要取消注释表单属性列表中的action="/registration"

Removing onsubmit="loadPage('registration')" and uncommenting the submitHandler part should do the job. Also uncomment the action="/registration" in the form's attribute list

这篇关于jQuery验证完成后,将省略表单发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆