Form Validation Callbacks Not Working - El Forum - 02-22-2010
[eluser]ShoeLace1291[/eluser]
I have a login form that has two fields: email and password. Here are some descriptions of the callbacks I use for the email field:
email_exists: Finds number of rows in the table where email = string
is_active: if the column in the member's table row called "isActive" = 0, return false(member account is inactive
Callback for password:
correct_pass: Finds row based on post input from email field and returns false if provided password does not match password on record.
This is my controller:
Code: <?php
class Login extends Controller {
function index(){
$this->template->head($title = "Member Login", FALSE);
if(($this->config->item('maintenance_mode') == TRUE) && ($this->session->userdata('permission') != 1)){
$variables = array(
'ERROR_HEADING' => "Maintenance Mode",
'ERROR_MESSAGE' => $this->config->item('maintenance_message')
);
$this->parser->parse('error_body', $variables);
} else {
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email|email_exists|is_active');
$this->form_validation->set_rules('password', 'Password', 'required|correct_pass');
if($this->form_validation->run() == FALSE){
$variables = array(
'FORM_OPEN' => form_open('login', array('onsubmit' => 'validateLogin();')),
'VALIDATION_ERRORS' => validation_errors()
);
$this->parser->parse('form_login', $variables);
} else {
if(!$this->member->login($this->input->post('email'))){
$error = array(
'ERROR_HEADING' => "System Error",
'ERROR_MESSAGE' => "The system encountered an error. Please try again later.".mysql_error()
);
$this->parser->parse('error_body', $error);
} else {
$error = array(
'ERROR_HEADING' => "Thank You!",
'ERROR_MESSAGE' => "Welcome back! You are now being redirected back to the index.".redirect('main', 'location')
);
$this->parser->parse('error_body', $error);
}
}
}
$this->load->view('overall_footer');
}
function email_exists($str){
$query = $this->db->query("SELECT * FROM members WHERE emailAddress = '".$str."'");
if($query->num_rows() == 0){
$this->form_validation->set_message('email_exists', 'The email address you provided does not exist in our database.');
return FALSE;
} else {
return TRUE;
}
}
function is_active($str){
$query = $this->db->query("SELECT * FROM members WHERE emailAddress = '".$str."' LIMIT 1");
$member = $query->row();
if($query->num_rows() == 0){
$this->form_validation->set_message('is_active', 'The email address you provided does not exist in our database.');
return FALSE;
} else if($member->isActive == 0){
$this->form_validation->set_message('is_active', 'The account you are trying to login to has not been activated.');
return FALSE;
} else {
return TRUE;
}
}
function correct_pass($str){
$query = $this->db->query("SELECT * FROM members WHERE emailAddress = '[email protected]'");
$member = $query->row();
if($query->num_rows() == 0){
return FALSE;
} else if(sha1($str) != $member->password){
$this->form_validation->set_message('correct_pass', 'The password you entered is incorrect.');
return FALSE;
} else {
return TRUE;
}
}
}
This is my form:
Code: <div id='mainBody'>
<div id='wideBox'>
<h1>Member Login</h1>
<ul>
{VALIDATION_ERRORS}
</ul>
{FORM_OPEN}
<table align='center' cellspacing='1' cellpadding='3' border='0'>
<tr>
<td align='right'>Email: </td>
<td align='left'><input type='text' name='email' size='30' /></td>
</tr><tr>
<td align='right'>Password: </td>
<td align='left'><input type='password' name='password' size='30' /></td>
</tr><tr>
<td align='center' colspan='2'><input type='submit' name='submit' value='Login' /></td>
</tr>
</table>
</div>
</div>
Form Validation Callbacks Not Working - El Forum - 02-23-2010
[eluser]mohsin917[/eluser]
It might help you. Callback
Form Validation Callbacks Not Working - El Forum - 02-23-2010
[eluser]heavenquake[/eluser]
You need to prefix callback functions with "callback_" in the form_validation rule you set. E.g, to have correct_pass() called as a callback, the rule needs to be "callback_correct_pass". The method name stays the same as currently, although you might want to make it CI private ( prefix with an underscore "_correct_pass()" - this way people can't access the method through the URL. REMEMBER to add this extra underscore to your callback rule, så callback_correct_pass becomes callback__correct_pass. IF you choose to use this, that is :0)
Form Validation Callbacks Not Working - El Forum - 04-06-2011
[eluser]Unknown[/eluser]
HI,
Call back function work well in 1.7.2 version. But it is not work in 2.0.0 version..kindly post any solution for my question??????
|