Welcome Guest, Not a member yet? Register   Sign In
Validation ...
#8

[eluser]llbbl[/eluser]
http://ellislab.com/codeigniter/user-gui...ation.html

Read everything on that page throughly. Try the examples. It helps. Wink


If you want set your own error message other than the default one use this:

Code:
$this->validation->set_message('required', 'Your custom message here');

That will change the error message for any field that is checking for the rule "required".

Quote:required No Returns FALSE if the form element is empty.


................................


Ok so if you want to check for something else like if the field exists already in the database this is one way to do it.

in a controller:
- do the built in validation
- if no errors w/ built in validation, call a function in some library
- if field exists set $error = 'username' then return error
- if field doesnt exist insert or whatever set $error = 'success' then return error
- check value of error
- if error = username

Code:
// basic controller junk
// some function stuff ---> basically what you see on the user guide

if ($error == "username"){
$rules['username']  = "callback_username_check";
$this->validation->set_rules($rules);
$this->validation->run();
$this->load->view('myform');
}

//////////////
// if statement and other code for if $error == "success"
//////////////

} // end function

function username_check($str){
  $this->validation->set_message('username_check', 'username taken dumbass');
  return FALSE;    
}


Messages In This Thread
Validation ... - by El Forum - 09-24-2007, 07:45 PM
Validation ... - by El Forum - 09-25-2007, 11:21 AM
Validation ... - by El Forum - 09-25-2007, 12:14 PM
Validation ... - by El Forum - 09-25-2007, 12:26 PM
Validation ... - by El Forum - 09-25-2007, 01:23 PM
Validation ... - by El Forum - 09-26-2007, 06:27 AM
Validation ... - by El Forum - 10-03-2007, 10:21 PM
Validation ... - by El Forum - 10-03-2007, 10:47 PM
Validation ... - by El Forum - 10-03-2007, 10:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB