[eluser]luffy[/eluser]
hi, everybody. I have worte some code. I don't whether it is better.
In the business model, I wrote one function
Code:
function set_validation_rules($controller, $form_name)
{
$controller->load->library('form_validation');
$fields = $this->forms[$form_name];
foreach ($fields as $field) {
$controller->form_validation->set_rules($field,
$this->form_fields[$field], $this->rules[$field]);
}
}
In the construction model:
Code:
function business_model()
{
parent::Model();
$this->form_fields = array('pwd'=> 'Password',
'newpwd'=> 'Password',
'newpwd2' => 'Retype password');
$this->rules = array('pwd' => 'trim|required|min_length[6]|max_length[14]',
'newpwd' => 'trim|required|min_length[6]|max_length[14]|matches[newpwd2]',
'newpwd2' => 'trim|required|min_length[6]|max_length[14]');
$this->forms = array('password_modification_form' => array('pwd', 'newpwd', 'newpwd2'),
);
}
in the business controll:
Code:
$this->business->set_validation_rules($this, 'password_modification_form');
How about these above?
Finally, I just need write one line to validate the form.