Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending additional static parameter with jquery remote validation

I want to send an extra parameter to the validation server side script. I have this code:

$("#edit_info").validate({
                debug: false,
              rules: {
                name: {
                    required: true,
                    //remote: "validate.php",
                    remote: { url:"validate.php", async:false },
                    data: {'cat_id':'34'}
                    /*data: {
                      cat_id: function () { return '34'; }
                    }*/
                },

But only the name gets sent. Any idea why? Thanks!

like image 387
Cornwell Avatar asked Sep 02 '26 16:09

Cornwell


2 Answers

In case you want to send dynamic parameters, instead of static:

$("#edit_info").validate({
        debug: false,
      rules: {
        name: {
            required: true,
            remote: { 
                url:"validate.php", 
                data: {'cat_id':function(){return $('#otherelement').val()}},
                async:false 
            }
        },
like image 197
JoeGalind Avatar answered Sep 05 '26 11:09

JoeGalind


Found out what the problem was. data must be inside the remote tags...

$("#edit_info").validate({
            debug: false,
          rules: {
            name: {
                required: true,
                remote: { 
                    url:"validate.php", 
                    data: {'cat_id':'34'},
                    async:false 
                }
            },
like image 44
Cornwell Avatar answered Sep 05 '26 11:09

Cornwell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!