Welcome Guest, Not a member yet? Register   Sign In
Issue with JQuery remote validation or Codigniter syntax?
#1

[eluser]Dandy_andy[/eluser]
I have an issue with a JQuery remote validation in my Codeigniter project. I'm not sure if this is a problem with the JQuery side or Codeigniter.

I have two remote requests from a form, one calling to search for usernames that already exist and the other to call for emails that already exist. The username remote request works fine but for some reason the email one doesn't work at all (it did work up until a week ago and I can't remember what, if anything, I changed to stop it from working).

Bearing in mind the username request is working fine, am I missing something obvious for the email remote request???

The relevant part of my view is:-

Code:
<form method="post" action="<?php echo base_url('register/verify'); ?>" class="form-horizontal" id="registerform" name="registerform">
  
      <fieldset>
      
            <div class="control-group">      
            <label class="control-label" for="usernamenew"><strong>Select a username</strong></label>
         <div class="controls">
                &lt;input type="text" class="span3" id="usernamenew" name="usernamenew" placeholder="Enter unique username" /&gt;
                &lt;!---<div class="alert alert-error"></div>---&gt;
         </div>
            </div>
    
      <div class="control-group">  
            <label class="control-label" for="em"><strong>Your email</strong></label>
         <div class="controls">
             &lt;input type="text" class="span3" id="em" name="em" placeholder="Your email address" /&gt;
             &lt;!---<div class="alert alert-error"></div>---&gt;
         </div>
            </div>
                
            
         <div class="controls">
         &lt;input type="submit" class="btn-large btn-danger" value="Submit" /&gt;
   </div>

      </fieldset>
      &lt;/form&gt;

[removed]
  $(document).ready(function(){
   $("#registerform").submit(function() {
   return $("#registerform").valid();
   });
   $("#registerform").validate({
    rules:{
     usernamenew:{required:true, alphanumeric:true, rangelength:[4, 20], remote:{url:"&lt;?php echo base_url('register/check_username'); ?&gt;", type:"post", data:$("usernamenew").val()}},
     password:{required:true, minlength:6},
     confirm_password:{required:true, equalTo:"#password"},
     em:{required:true, email:true, remote:{url:"&lt;?php echo base_url('register/check_email'); ?&gt;", type:"post", data:$("em").val()}},
     verify:{required:true},
     terms:{required:true}
    },
    messages:{
     usernamenew:{rangelength:"Must be between 4 and 20 characters", remote:"Username already exists. Please choose another"},
     password:{required:"Please enter a password", minlength:"Password must have at least 6 characters"},
     confirm_password:{required:"Please confirm your password", equalTo:"Password and Confirm Password must match"},
     em:{required:"Enter your email address", remote:"That email is already in use. Please choose another"},
     verify:{required:"<---"},
     terms:{required:">"}
    },
    errorClass: "help-inline",
    errorElement: "span",
    highlight:function(element, errorClass, validClass) {$(element).parents('.control-group').addClass('error');},
    unhighlight:function(element, errorClass, validClass) {$(element).parents('.control-group').removeClass('error'); $(element).parents('.control-group').addClass('');}
   });
  });
[removed]

My Controller has the following functions:-

Code:
public function check_username() {

  $this->load->model('user_model');
  $usr = $this->input->post('usernamenew');
  $resultusername = $this->user_model->check_username_exist($usr);
  if($resultusername)
   {
   echo "false";
   }
   else
   {
   echo "true";
   }
}//function check_username




public function check_email() {

  $this->load->model('user_model');
  $em = $this->input->post('em');
  $result = $this->user_model->check_email_exist($em);
  if($result)
   {
   echo "false";
   }
   else
   {
   echo "true";
   }
}//function check_username

And my model uses:-

Code:
//check username address doesn't already exist during registration
public function check_username_exist($usr) {

  $this->db->where("username", $usr);
  $query = $this->db->get("members");
  
  $this->db->where("username", $usr);
  $query2 = $this->db->get("verification");
  
  if (($query->num_rows()>0) or ($query2->num_rows()>0))
   {
   return true;
   }
   else
   {
   return false;
   }
  
}


//check email address doesn't already exist during registration
public function check_email_exist($em) {

  $this->db->where("email", $em);
  $query = $this->db->get("members");
  
  $this->db->where("email", $em);
  $query2 = $this->db->get("verification");
  
  $this->db->where("email", $em);
  $query3 = $this->db->get("banned_email");
  
  $this->db->where("new_email", $em);
  $query4 = $this->db->get("verification_email");
  
  if (($query->num_rows()>0) or ($query2->num_rows()>0) or ($query3->num_rows()>0) or ($query4->num_rows()>0))
   {
   return true;
   }
   else
   {
   return false;
   }
  
}

Any ideas why the username remote query works but my email one doesn't? They essentially have the same functions so I am very confused...

Thanks


Messages In This Thread
Issue with JQuery remote validation or Codigniter syntax? - by El Forum - 09-07-2012, 12:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB