Welcome Guest, Not a member yet? Register   Sign In
set_value() and callbacks
#1

[eluser]Unknown[/eluser]
hi!
why is is that every time i use callbacks,
the form does not echo the input value enymore?
please help.
thanks!

CONTROLLER:
Code:
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[6]|callback__validate_username');
VIEW:
Code:
echo '<tr><th>Username<span class="req">*</span></th><td>'.form_input('username', set_value('username')).'</td><td>'.form_error('username','<div class="error">','</div>').'</td></tr>';
MODEL:
Code:
function checkUsername()
{
$this->db->where('username', $this->input->post('username'));
$query = $this->db->get('membership');
if($query->num_rows == 1)
{
return TRUE;
}
}
#2

[eluser]Pascal Kriete[/eluser]
Callbacks can return one of two things:
- A boolean (TRUE / FALSE) to indicate a passed or failed rule.
- A string that will be used as the new value. Trim, for example, does this.

We check the type of the return value (is_bool()), so in your example you need to explicitly return FALSE if it fails.

Code:
return ($query->num_rows == 1) ? TRUE : FALSE;
#3

[eluser]Unknown[/eluser]
got it!
thank you so much. Smile




Theme © iAndrew 2016 - Forum software by © MyBB