views:

159

answers:

4
+1  Q: 

Remote validation

below is my code the validation only works without the remote validation. once i include remote validation, it submit the form without completing all the other form validations?

    $(document).ready(function() {


      $("#form1").validate({
            rules: {
                firstName: "required",// simple rule, converted to {required:true}
                lastName: "required",
                email: {// compound rule
                        required: true,
                        email: true,
                        success: "valid",
                        remote: "checkAddress.php"
                },      
                password: {
                    required: true,
                    success: "valid",
                    minlength: 5
                },

                verify: {
                    required: true,
                    success: "valid",
                    minlength: 5,
                    equalTo: "#password"
                },
                address1: "required",
                city: "required",
                province: "required",

                dob: {
                    required: true,
                    date: true,
                    success: "valid"
                },


                captcha_code: {
                    required: true,
                    captcha_code: true,
                    remote: "checkCaptcha.php"      
                }   

            },
            messages: {
               email:{
                   remote: "This email is already registered! One registration per email address."
               },
               captcha_code:{
                  remote: "Enter the right captcha value!."
               }
            },
            onsubmit: true
        });
    });
A: 

The remote URL is hit passing in the value of the field to which it’s expecting a JSON TRUE/FALSE in return, are you in this one?

Reigel
yes i already have a json true/false. strangely my form omits the rest of the validation. i can't seem to find the reason?
Menew
how about putting this header('Content-type: application/json');then echo $output; I think json_encode returns an array in form...
Reigel
basically, if a user enter a value for "email" and the captcha, it omits the rest of the form validation, and the form submits. maybe remote validation is not that efficient in jquery. here is the error i am getting: Error: $.validator.methods[method] is undefined on line 471 of jquery.validator
Menew
captcha_code: { required: true, captcha_code: true, remote: "checkCaptcha.php" }are you defining captcha_code? for "captcha_code: true,"
Reigel
yes here is my form captcha: <div class="form-row"> <img id="captcha" src="securimage/securimage_show.php" alt="CAPTCHA Image" /> <input type="text" name="captcha_code" size="6" maxlength="6" /> <a href="#" onclick="document.getElementById('captcha').src = 'securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a> </div> i am getting captcha code from here: http://www.phpcaptcha.org/
Menew
A: 

at the moment, i have disabled all the jquery remote referencing to make my form validates. i wish there was a way to remotely validated the form; i tried everything, and each time the remote validation is done, the rest of the form validation gets ignored.

Menew
A: 

What I was asking was if you have implemented captcha_code as a method? in captcha_code: true,.

 captcha_code: {
      required: true,
      captcha_code: true,
      remote: "checkCaptcha.php"      
 }   

Like this

jQuery.validator.addMethod("captcha_code", function(value, element) {
    return (this.optional(element) || /* do something */ );
}, "");

I found this captcha demo and it has no captcha_code as method, only required and remote. So I was thinking if you have implemented it.

Here is the script from the demo. http://jquery.bassistance.de/validate/demo/captcha/

$(function(){
$("#refreshimg").click(function(){
    $.post('newsession.php');
    $("#captchaimage").load('image_req.php');
    return false;
});

$("#captchaform").validate({
    rules: {
        captcha: {
            required: true,
            remote: "process.php"
        }
    },
    messages: {
        captcha: "Correct captcha is required. Click the captcha to generate a new one" 
    },
    submitHandler: function() {
        alert("Correct captcha!");
    },
    success: function(label) {
        label.addClass("valid").text("Valid captcha!")
    },
    onkeyup: false
});

});

Reigel
what is "captcha_code: true," for?
Reigel
ah, i never implemented "captcha_code: true" i thought thats how its done in jquery. i am very new to jquery so i just thought thats how its done. maybe thats where the error is?
Menew
try taking that out... "captcha_code: true,", i think it will work perfectly... or let me know what are you trying to do with that.
Reigel
glad i could help... :)
Reigel
please choose me as your best answer... thanks...
Reigel
A: 

so i changed: [code] email: {// compound rule required: true, email: true, success: "valid", remote: "checkAddress.php" }, captcha_code: { required: true, captcha_code: true, remote: "checkCaptcha.php"
}
[/code]

to [code] email: {// compound rule required: true,
remote: "checkAddress.php" }, captcha_code: { required: true, remote: "checkCaptcha.php"
}
[/code]

it works great, wow, you guys rock!!!

Menew