如何暂停表单提交,最后一次验证,最后一次验证,发布后/触发/继续提交?

时间:2011-04-06 18:41:13

标签: javascript jquery ajax validation

我有一个page1.php,我有一个fly.php。 page1.php是一个简单的(常规)表单页面,人们在用户提交表单时放置信息。

  • 通过ajax加载验证码模板并要求即时验证(直到这里很好)。
  • 在onFly验证后,我想允许这个.submit()继续

问题:此验证码的How can i after .submit() pause for validatio n和验证成功后,恢复表单提交(暂停)?

示例:

第1部分:page1.php

$(document).ready(function()
{
 $('.callmeback').submit(function()
 {
    $.ajax({
        type    : "GET",
        url     : "/include/class/fly.php",
        data    : "a=b",
        async   : false,
        beforeSend: function()
        {
            $(document.body).find('.blackwindow').remove();
            $(document.body).find('.nospam').remove();  
        },  
        complete: function()
        {
        },      
        success : function(msg)
        {
           $(document.body).append(msg);
           $('.blackwindow').css({
              'opacity':'0.90'
           });

           $('.nospam').find('input[type="button"]').live("click", function()
           {
              // final validation
              var security= $('.nospam').find('#security').val();
              var random  = $('.nospam').find('#random').val();

                  if (random!=security)
              { 
            alert ('Invalid captcha.');
            return false;

               } else  {
            // Basically its second time? and return true?                      
               }

           });

        }

    });

    //return false;
 });

});

<form method=post action=thanks.php class="callmeback">
<input type=text value=100.00 name=amount />
<input type=submit value=submit name=submit />
</form>

第2部分:fly.php

<? require_once 'obj.php';?>
.blackwindow {
        position:fixed;
        top:0px;
        left:0px;
        width:100%;
        height:100%;
        z-index:1000;

        background-color:#000000;
}

.nospam {
        position:fixed;
        top:30%;
        left:30%;
        padding:12px;
        border:solid 3px #686868;
        background-color:#ffffff;
        z-index:1001;
}
<div class="blackwindow"></div>
<div class="nospam">
<div>
<?
$value = obj::getRandom();                                          
echo '<img src="include/class/return_img.php?number=' . $value . '" />';
echo "<input type='hidden' id='random' name='random' value='$value' />";
?>     
<div>
*Please enter the above code below, to verify this request <br/>
<input type="text" class="textbox" id="security" name="security" />
</div>
</div>
<div>
<input type=button name=mybutton value="Verify" />
</div>
</div>

跟进(校对):

$(document).ready(function()
{
 $('.callmeback').find('input[type="button"]').live("click", function()
 {
    $.ajax({
        type    : "GET",
        url     : "/include/class/fly.php",
        data    : "a=b",
        async   : false,
        beforeSend: function()
        {
            $(document.body).find('.blackwindow').remove();
            $(document.body).find('.nospam').remove();  
        },  
        complete: function()
        {
        },      
        success : function(msg)
        {
           $(document.body).append(msg);
           $('.blackwindow').css({
              'opacity':'0.90'
           });

           $('.nospam').find('input[type="button"]').live("click", function()
           {
              // final validation
              var security= $('.nospam').find('#security').val();
              var random  = $('.nospam').find('#random').val();

                  if (random!=security)
              { 
            alert ('Invalid captcha.');
            return false;

               } else  {
            $('.callmeback').submit();                      
               }

           });

        }

    });

    //return false;
 });

});

1 个答案:

答案 0 :(得分:4)

最简单的方法是使“提交”按钮实际上不是<input type='submit'>按钮,而只是标准button。如果验证通过,您可以使用$('form').submit()或类似的东西手动提交论坛。