[eluser]mTuran[/eluser]
Hi everone. i am developing my first MVC pattern app and have few questions about ci.
1-) i do validation like below but i didn't understand what for trim or xss clean validation options. Normally they are used for trim string or clean string against xss codes but "$this->form_validation->set_rules('i_fullname', 'lang:fullname', 'trim|required|xss_clean');" this line only set rule, don't manupulate i_fullname input with trim or xss clean also this line doesn't return any manupulated value.
Code:
// Collectiong User Input
$fullname = ucwords($this->input->post('i_fullname'));
$birthdate= convert_datetime($this->input->post('i_birthdate'), 'mysql');
$country= ucwords($this->input->post('i_country'));
$city = ucwords($this->input->post('i_city'));
$email = $this->input->post('i_email');
$username = $this->input->post('i_username2');
$password = $this->input->post('i_password2');
$password_confirm = $this->input->post('i_password2_confirm');
$captcha = strtoupper($this->input->post('i_captcha'));
// Validation
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<span class="info error">', '</span>');
$this->form_validation->set_rules('i_fullname', 'lang:fullname', 'trim|required|xss_clean');
$this->form_validation->set_rules('i_birthdate', 'lang:birthdate', 'trim|required|xss_clean');
$this->form_validation->set_rules('i_country', 'lang:country', 'trim|required|xss_clean');
2-) I wrote example of my controller, my code logic is like that. am i doing MVC pattern with proper way ? Can you suggest better coding patterns ?
Code:
function email_confirmation($membership_type)
{
// Collectiong User Input
$email = $this->input->post('i_email');
// Validation
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('i_email', 'lang:email', 'trim|required|valid_email|xss_clean|callback__email_check');
if (!$this->form_validation->run())
{
$data['content'] = $this->load->view('hesap/register_email_confirmation_view.php', '', TRUE);
}
else
{
// Sending confirmation e-mail
$this->my_user->send_confirmation_email($email, $membership_type);
$content_data = array(
'email' => $email
);
$data['content'] = $this->load->view('hesap/register_email_confirmation_sended_view.php', $content_data, TRUE);
}
// Page data
$data['page_title'] = 'My Page';
$data['page_description'] = 'example description';
$data['js'] = '$(function() { hesap = new exampleJsClass(); });';
$this->load->vars($data);
$this->load->view('layout/default');
}
3-) I want to use validation callbacks global. For example i have callback like below i want to use that in many controllers, i don't want rewrite same code again. What is proper way of done that ?
Code:
function _username_check($username)
{
if (!$this->user->is_username_available($username))
{
$this->form_validation->set_message('_username_check', $this->lang->line('not_available_resource'));
return FALSE;
}
if(preg_match('/[^A-Za-z0-9_$]/', $username))
{
$this->form_validation->set_message('_username_check', $this->lang->line('valid_username'));
return FALSE;
}
return TRUE;
}
Thank you very much