Welcome Guest, Not a member yet? Register   Sign In
Form validation jquery problem
#4

[eluser]nuwanda[/eluser]
I'll try to make this clearer for you:

Create a controller method that does something like this to check if the account name is taken:

Code:
function exists(){

  $account_name = $this->input->post('account_name');

  $table = your_table;    
  $column = your_column;

  $query = $this->db->query("SELECT COUNT(*) AS count FROM $table WHERE $column = '$account_name'");

  $row = $query->row();
            
  if($row->count > 0){

    echo "Account name already exists";

  }else{

    echo "Account name is available";

  }

}

Note the use of echo to return output to the ajax call.

Then your ajax:

Code:
var account_name_value = $('#account_name_input').val();

$.ajax({
  type: "POST",
  url: "/controller/exists",
  data: ({account_name: account_name_value}),
  dataType: "html",    
  success: function (result) {
    //update page with result from exists function
  }
});


Messages In This Thread
Form validation jquery problem - by El Forum - 11-26-2010, 04:59 AM
Form validation jquery problem - by El Forum - 11-26-2010, 03:13 PM
Form validation jquery problem - by El Forum - 11-26-2010, 03:18 PM
Form validation jquery problem - by El Forum - 11-26-2010, 03:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB