CodeIgniter Forums
set_value() and callbacks - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: set_value() and callbacks (/thread-33890.html)



set_value() and callbacks - El Forum - 09-11-2010

[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;
}
}



set_value() and callbacks - El Forum - 09-12-2010

[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;



set_value() and callbacks - El Forum - 09-13-2010

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