【问题标题】:php jquery, validate remote , arrayphp jquery,验证远程,数组
【发布时间】:2012-10-02 07:42:50
【问题描述】:

我在运行以下代码时遇到了一些问题,js:

 $(document).ready(function(){
$.validator.addMethod("name", function(value, element) {
    return $("#identiPIC_selected_0").val() !== '' &&    $("#identiPIC_selected_1").val() !== '' ;
}, "Required!");

$("#signin").validate({
    groups:{
         name : 'identiPIC_selected[]'  
    },
    rules: {
        'identiPIC_selected[]': {
            required: true,
            remote: { 
                url:"check3.php",
                type:"post",
                cache: false,
                async:false,
                data: {
                    'identiPIC_selected[0]': function() {
                        return $.trim($("#identiPIC_selected_0").val());
                    },
                    'identiPIC_selected[1]': function() {
                        return $.trim($("#identiPIC_selected_1").val());
                    }
                }
            }
        }
    }
});

});

php 如下:

<?php
 $captcha = $_POST['identiPIC_selected'];
$identiPIC[0] = "Apple";
$identiPIC[1] = "Flower";
 if($captcha === $identiPIC){
    echo "true";
 } else {
    echo "false";
 }

?>

和html:

<form id="signin" action="check3.php" method="POST">
<select id="identiPIC_selected_0" name="identiPIC_selected[]">
<option value="">Click to identify</option>
<option>Apple</option>
<option>Cat</option>
<option>Clock</option>
<option>Flower</option>
<option>Fork</option>
</select>
<select id="identiPIC_selected_1" name="identiPIC_selected[]">
<option value="">Click to identify</option>
<option>Apple</option>
<option>Cat</option>
<option>Clock</option>
<option>Flower</option>
<option>Fork</option>
</select>
<input type="submit" id="save" name="save" value="Save"/>
</form>

这段代码运行良好,除非用户选择了第二个“选择”选项错误,按下提交然后修复他的错误,然后他按下提交它只是不再提交,所以我的意思是例如:

用户选择:Apple + Cat 并点击保存按钮,显示错误, 用户修复问题:Apple+Flower,点击保存按钮,没有提交,即使所有的pick都很好。

我添加了这个:

$("#identiPIC_selected_0").change(function () {
    $("#identiPIC_selected_0").removeData("previousValue");
});
$("#identiPIC_selected_1").change(function () {
   $("#identiPIC_selected_1").removeData("previousValue");
});

但它似乎对我没有任何作用。 有人有什么想法吗? 谢谢!!!

【问题讨论】:

    标签: validation jquery jquery-validate


    【解决方案1】:

    好的...经过不同的尝试,我认为我找到了解决方案,这似乎可行:

       $('#signin').submit(function(){
        $("#identiPIC_selected_0").removeData('previousValue');
        $("#identiPIC_selected_1").removeData('previousValue');
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 2013-01-20
      • 2011-01-28
      相关资源
      最近更新 更多