Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14348

Ajax validation issue with array

$
0
0
I am trying to validate my codeigniter based from using jquery ajax.  in my form i have dynamic fields which generates fields name like fault[0],fault[1],fault[2]......  this jquery script i am using works only  the ID attribute & NAME attribute of a field are same. since array fields have [] marks i am unable to validate them. 

i need to know a way doing this without id & same name rule. 

i think this part manages the validate the fields only with same name & id.



Code:
$.each(response.messages, function(key, value) {
           var element = $('#' + key);



PHP Code:
$('#form-user').submit(function(e) {
 
   e.preventDefault();

 
   var me = $(this);

 
   // perform ajax
 
   $.ajax({
 
     urlme.attr('action'),
 
     type'post',
 
     datame.serialize(),
 
     dataType'json',
 
     success: function(response) {
 
       if (response.success == true) {
 
         // if success we would show message
 
         // and also remove the error class
 
         $('#the-message').append('<div class="alert alert-success">' +
 
           '<span class="glyphicon glyphicon-ok"></span>' +
 
           ' Data has been saved' +
 
           '</div>');
 
         $('.form-group').removeClass('has-error')
 
                 .removeClass('has-success');
 
         $('.text-danger').remove();

 
         // reset the form
 
         me[0].reset();

 
         // close the message after seconds
 
         $('.alert-success').delay(500).show(10, function() {
 
           $(this).delay(3000).hide(10, function() {
 
             $(this).remove();
 
           });
 
         })
 
       }
 
       else {
 
         $.each(response.messages, function(keyvalue) {
 
           var element = $('#' key);
 
           
            element
.closest('div.form-group')
 
           .removeClass('has-error')
 
           .addClass(value.length 'has-error' 'has-success')
 
           .find('.text-danger')
 
           .remove();
 
           
            element
.after(value);
 
         });
 
       }
 
     }
 
   });
 
 }); 

Viewing all articles
Browse latest Browse all 14348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>