⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Validation rule 3 field?



Harasya
  • profile picture
  • Member

Posted 26 March 2013 - 10:53 AM

how to make a validation rule 3 fields
example
 
schedule
-----------------------
day
hour
lecturer
class
 
days, hours, classes can not be same,
will come out a warning that the class, hours, and lecturers already in use
thank you.....................

Harasya
  • profile picture
  • Member

Posted 28 March 2013 - 16:15 PM

function jadwal() {
        $crud = new grocery_CRUD();
        $crud->set_theme('datatables');
        $crud->set_table('jadwal');
        $crud->set_subject('Jadwal');
        $crud->display_as('thakademik_idthakademik', 'Tahun Akademik');
        $crud->display_as('dosen_nik', 'Dosen');
        $crud->set_subject('Jadwal Pelajaran');
        $crud->set_relation('matakuliah_kode', 'matakuliah', 'nama');
        $crud->set_relation('dosen_nik', 'dosen', 'nama');
        $crud->set_relation('thakademik_idthakademik', 'thakademik', '{tahun_awal}/{tahun_akhir} / {semester}');
        $crud->set_rules('hari', 'Hari', 'required');
        $crud->set_rules('jam_mulai', 'Jam Mulai', 'required|callback_jadwal_check');
        $crud->set_rules('jam_selesai', 'Jam Selesai', 'required');
        $crud->set_rules('kelas', 'Kelas', 'required|callback_jadwal_check');
        $crud->set_rules('thakademik_idthakademik', 'Tahun Akademik', 'required');
        $crud->set_rules('matakuliah_kode', 'Matakuliah', 'required');
        $crud->set_rules('dosen_nik', 'Dosen', 'required');
        $crud->unset_print();
        $crud->unset_export();
        $output = $crud->render();
        $this->_administrator_output($output);
    }

    public function jadwal_check($kelas, $jam_mulai) {
        $jdwl = $this->uri->segment(4);
        if (!empty($jdwl) && is_numeric($jdwl)) {
            $jdwl_old = $this->db->where("thakademik_idthakademik", $jdwl)->get('jadwal')->row()->jam_mulai;
            $this->db->where("jam_mulai !=", $jdwl_old);
            $jdwl_old_kelas = $this->db->where("thakademik_idthakademik", $jdwl)->get('jadwal')->row()->kelas;
            $this->db->where("kelas !=", $jdwl_old_kelas);
        }

        $num_row = $this->db->where('jam_mulai', $jam_mulai)->get('jadwal')->num_rows();
        $num_row_kelas = $this->db->where('kelas', $kelas)->get('jadwal')->num_rows();
        if (($num_row >=1)&&( $num_row_kelas >= 1)) {
            $this->form_validation->set_message('jadwal_check', 'Jadwal sudah dipakai');
            return FALSE;
        } else {
            return TRUE;
        }
    }

 

no work in me..........