P EMROGRAMAN W EB II Lasmedi afuan, ST.,M.Cs
T OPIC Validation Class
F ORM VALIDATION CLASS CI menyediakan class yang dapat digunakan untuk melakukan validasi terhadap data yang dimasukkan melalui form Class tersebut adalah form validation class
F ORM VALIDATION CLASS $this->load->library(‘form_validation’);
P EMANGGILAN CLASS FORM VALIDATION Memanggil Library Form Validation $this->load->library(‘form_validation’);
M ETHOD DALAM FORM VALIDATION CLASS $this->form_validation->Set _rules(‘field_name’,’Label Pesan Error’,’Aturan1|aturan2|aturan3’); $this->form_validation-> Run(); $this->form_validation-> Set_message(‘aturan’,’Pesan dalam bahasa indonesia’);
$this->load->helper('form'); $this->load->library('form_validation'); $this->form_validation->set_rules('username','Username ','required|min_length[5]'); $this->form_validation->set_rules('password','Password ','required'); $this->form_validation->set_rules('password1','Password ','required'); if ($this->form_validation->run() == FALSE) { $this->load->view('tambah_user'); } else { $this->load->view('tambah_user'); }
validation_errors() Form_error(‘namafield’);