Trigger and form codeigniter - mysql

I have a database and form with some trigger in phpmyadmin. When I input the value manually on phpmyadmin, the trigger is executed normally. The problem is, when I input the value by form I made with codeigniter, the trigger is not executed, and there is no error. Can anybody help me?
This is the controller
<?php if (!defined('BASEPATH')) exit ('No direct script access allowed');
class Pengujian extends MY_Controller
{
public $data = array(
'modul' => 'pengujian',
'breadcrumb' => 'Pengujian',
'pesan' => '',
'pagination' => '',
'tabel_data' => '',
'main_view' => 'view_pengujian/pengujian_view',
'form_action' => '',
'form_value' => '',
'option_uji' => '',
);
public function __construct()
{
parent::__construct();
$this->load->model('Pengujian_model', 'pengujian', TRUE);
$this->load->model('Peralatan_model', 'peralatan', TRUE);
$this->load->model('Penerangan_model', 'penerangan', TRUE);
$this->load->model('Kemudi_model', 'kemudi', TRUE);
$this->load->model('Suspensi_model', 'suspensi', TRUE);
$this->load->model('Banpelek_model', 'banpelek', TRUE);
$this->load->model('Rangka_model', 'rangka', TRUE);
$this->load->model('Rem_model', 'rem', TRUE);
$this->load->model('Gasbuang_model', 'gasbuang', TRUE);
$this->load->model('Mesin_model', 'mesin', TRUE);
$this->load->model('Lainlain_model', 'lainlain', TRUE);
$this->load->model('Lainlain2_model', 'lainlain2', TRUE);
$this->load->model('Akhir_model', 'akhir', TRUE);
$this->load->helper('form');
//$this->load->model('Penguji_model', 'penguji', TRUE);
}
public function index($offset = 0)
{
$this->session->unset_userdata('no_pengujian_sekarang', '');
$pengujian = $this->pengujian->cari_semua($offset);
if ($pengujian)
{
$tabel = $this->pengujian->buat_tabel($pengujian);
$this->data['tabel_data'] = $tabel;
$this->data['pagination'] = $this->pengujian->paging(site_url('pengujian/halaman'));
}
else
{
$this->data['pesan'] = 'Tidak ada data pengujian';
}
$this->load->view('template', $this->data);
}
public function tambah1()
{
$this->data['breadcrumb'] = 'Pengujian > Tambah > Awal';
$this->data['main_view'] = 'view_pengujian/pengujian_form';
$this->data['form_action'] = 'pengujian/tambah1';
if($this->input->post('submit'))
{
if($this->pengujian->validasi_tambah())
{
if($this->pengujian->tambah1())
{
$this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
redirect('pengujian/tambah2');
}
else
{
$this->data['pesan'] = 'Proses tambah data gagal';
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
public function tambah2()
{
$this->data['breadcrumb'] = 'Pengujian > Tambah > Peralatan';
$this->data['main_view'] = 'view_pengujian/peralatan_form';
$this->data['form_action'] = 'pengujian/tambah2';
if($this->input->post('submit'))
{
if($this->peralatan->validasi_tambah())
{
if($this->peralatan->tambah2())
{
$this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
redirect('pengujian/tambah3');
}
else
{
$this->data['pesan'] = 'Proses tambah data gagal';
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
I have until tambah12 methods, for each method, it must load from 12 models too, and 12 forms.
This is model
private function load_form_rules_tambah()
{
$form = array(
array(
'field' => 'NO_PENGUJIAN',
'label' => 'no pengujian',
'rules' => 'required'
),
);
return $form;
}
public function validasi_tambah()
{
$form = $this->load_form_rules_tambah();
$this->form_validation->set_rules($form);
if($this->form_validation->run())
{
return TRUE;
}
else
{
return FALSE;
}
}
public function tambah1()
{
$pengujian = array(
'NO_PENGUJIAN' => $this->input->post('NO_PENGUJIAN'),
'NO_PEMERIKSAAN' => $this->input->post('NO_PEMERIKSAAN'),
'LOKASI_PENGUJIAN' => $this->input->post('LOKASI_PENGUJIAN'),
'NO_KODE' => $this->input->post('NO_KODE'),
'NO_KENDARAAN' => $this->input->post('NO_KENDARAAN'),
'PEMILIK_KENDARAAN' => $this->input->post('PEMILIK_KENDARAAN'),
'TYPE_MERK_PABRIK' => $this->input->post('TYPE_MERK_PABRIK'),
'JENIS_KENDARAAN' => $this->input->post('JENIS_KENDARAAN'),
'MULAI_DIPERGUNAKAN' => $this->input->post('MULAI_DIPERGUNAKAN'),
'NO_LAPORAN' => $this->input->post('NO_LAPORAN'),
'JENIS_PEMERIKSAAN' => $this->input->post('JENIS_PEMERIKSAAN'),
'JARAK_PEMAKAIAN' => $this->input->post('JARAK_PEMAKAIAN'),
'BERAT_KENDARAAN' => $this->input->post('BERAT_KENDARAAN'),
'PERALATAN' => $this->input->post('PERALATAN'),
'SISTEM_PENERANGAN' => $this->input->post('SISTEM_PENERANGAN'),
'SISTEM_KEMUDI' => $this->input->post('SISTEM_KEMUDI'),
'AS_DAN_SUSPENSI' => $this->input->post('AS_DAN_SUSPENSI'),
'BAN_DAN_PELEK' => $this->input->post('BAN_DAN_PELEK'),
'RANGKA_DAN_BODI' => $this->input->post('RANGKA_DAN_BODI'),
'SISTEM_REM' => $this->input->post('SISTEM_REM'),
'SISTEM_REM_GAS_BUANG' => $this->input->post('SISTEM_REM_GAS_BUANG'),
'MESIN_TRANSMISI' => $this->input->post('MESIN_TRANSMISI'),
'LAIN_LAIN' => $this->input->post('LAIN_LAIN'),
'LAIN_LAIN2' => $this->input->post('LAIN_LAIN2')
);
//$this->load->library('form_validation');
$this->db->insert($this->db_tabel, $pengujian);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
and this
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Peralatan_model extends CI_Model
{
public $db_tabel ='peralatan';
//public $offset = 0;
//public function cari_semua($offset = 0);
public function tambah2()
{
$peralatan = array(
'NO_CHASIS' => $this->input->post('NO_CHASIS'),
'PLAT_PABRIK_PEMBUAT' => $this->input->post('PLAT_PABRIK_PEMBUAT'),
'PLAT_NOMOR' => $this->input->post('PLAT_NOMOR'),
'TULISAN' => $this->input->post('TULISAN'),
'PENGHAPUS_KACA_DEPAN' => $this->input->post('PENGHAPUS_KACA_DEPAN'),
'KLAKSON' => $this->input->post('KLAKSON'),
'KACA_SPION' => $this->input->post('KACA_SPION'),
'PANDANGAN_KE_DEPAN' => $this->input->post('PANDANGAN_KE_DEPAN'),
'KACA_PENAHAN_SINAR' => $this->input->post('KACA_PENAHAN_SINAR'),
'ALAT_PENGENDALIAN' => $this->input->post('ALAT_PENGENDALIAN'),
'LAMPU_INDIKASI' => $this->input->post('LAMPU_INDIKASI'),
'SPEEDOMETER' => $this->input->post('SPEEDOMETER'),
'PERLENGKAPAN' => $this->input->post('PERLENGKAPAN')
);
//$this->load->library('form_validation');
$this->db->insert($this->db_tabel, $peralatan);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
private function load_form_rules_tambah()
{
$form = array(
array(
'field' => 'NO_PENGUJIAN',
'label' => 'no chasis',
'rules' => 'required'
),
);
return $form;
}
public function validasi_tambah()
{
$form = $this->load_form_rules_tambah();
$this->form_validation->set_rules($form);
if($this->form_validation->run())
{
return TRUE;
}
else
{
return FALSE;
}
}
}
this is the form
<?php
$form = array(
'no pengujian' => array(
'name' => 'NO_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PENGUJIAN', isset($form_value['NO_PENGUJIAN']) ? $form_value['NO_PENGUJIAN'] : '')),
'no pemeriksaan' => array(
'name' => 'NO_PEMERIKSAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PEMERIKSAAN', isset($form_value['NO_PEMERIKSAAN']) ? $form_value['NO_PEMERIKSAAN'] : '')),
'lokasi pengujian' => array(
'name' => 'LOKASI_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('LOKASI_PENGUJIAN', isset($form_value['LOKASI_PENGUJIAN']) ? $form_value['LOKASI_PENGUJIAN'] : '')),
'no kode' => array(
'name' => 'NO_KODE',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_KODE', isset($form_value['NO_KODE']) ? $form_value['NO_KODE'] : '')),
'no kendaraan' => array(
'name' => 'NO_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_KENDARAAN', isset($form_value['NO_KENDARAAN']) ? $form_value['NO_KENDARAAN'] : '')),
'pemilik kendaraan' => array(
'name' => 'PEMILIK_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('PEMILIK_KENDARAAN', isset($form_value['[PEMILIK_KENDARAAN]']) ? $form_value['PEMILIK_KENDARAAN'] : '')),
'type merk pabrik' => array(
'name' => 'TYPE_MERK_PABRIK',
'size' => '30',
'class' => 'form_field',
'value' => set_value('TYPE_MERK_PABRIK', isset($form_value['TYPE_MERK_PABRIK']) ? $form_value['TYPE_MERK_PABRIK'] : '')),
'jenis kendaraan' => array(
'name' => 'JENIS_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('JENIS_KENDARAAN', isset($form_value['JENIS_KENDARAAN']) ? $form_value['JENIS_KENDARAAN'] : '')),
'mulai dipergunakan' => array(
'name' => 'MULAI_DIPERGUNAKAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('MULAI_DIPERGUNAKAN', isset($form_value['MULAI_DIPERGUNAKAN']) ? $form_value['MULAI_DIPERGUNAKAN'] : '')),
'no laporan' => array(
'name' => 'NO_LAPORAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_LAPORAN', isset($form_value['NO_LAPORAN']) ? $form_value['NO_LAPORAN'] : '')),
'jenis pemeriksaan' => array(
'name' => 'JENIS_PEMERIKSAAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('JENIS_PEMERIKSAAN', isset($_POST['JENIS_PEMERIKSAAN']))),
'jarak pemakaian' => array(
'name' => 'JARAK_PEMAKAIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('JARAK_PEMAKAIAN', isset($form_value['JARAK_PEMAKAIAN']) ? $form_value['JARAK_PEMAKAIAN'] : '')),
'berat kendaraan' => array(
'name' => 'BERAT_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('BERAT_KENDARAAN', isset($form_value['BERAT_KENDARAAN']) ? $form_value['BERAT_KENDARAAN'] : '')),
'peralatan' => array(
'name' => 'PERALATAN',
'size' => '30',
'value' => set_value('PERALATAN', isset($form_value['PERALATAN']) ? $form_value['PERALATAN'] : '')),
'sistem penerangan' => array(
'name' => 'SISTEM_PENERANGAN',
'size' => '30',
'value' => set_value('SISTEM_PENERANGAN', isset($form_value['SISTEM_PENERANGAN']) ? $form_value['SISTEM_PENERANGAN'] : '')),
'sistem kemudi' => array(
'name' => 'SISTEM_KEMUDI',
'size' => '30',
'value' => set_value('SISTEM_KEMUDI', isset($form_value['SISTEM_KEMUDI']) ? $form_value['SISTEM_KEMUDI'] : '')),
'as dan suspensi' => array(
'name' => 'AS_DAN_SUSPENSI',
'size' => '30',
'value' => set_value('AS_DAN_SUSPENSI', isset($form_value['AS_DAN_SUSPENSI']) ? $form_value['AS_DAN_SUSPENSI'] : '')),
'ban dan pelek' => array(
'name' => 'BAN_DAN_PELEK',
'size' => '30',
'value' => set_value('BAN_DAN_PELEK', isset($form_value['BAN_DAN_PELEK']) ? $form_value['BAN_DAN_PELEK'] : '')),
'rangka dan bodi' => array(
'name' => 'RANGKA_DAN_BODI',
'size' => '30',
'value' => set_value('RANGKA_DAN_BODI', isset($form_value['RANGKA_DAN_BODI']) ? $form_value['RANGKA_DAN_BODI'] : '')),
'sistem rem' => array(
'name' => 'SISTEM_REM',
'size' => '30',
'value' => set_value('SISTEM_REM', isset($form_value['SISTEM_REM']) ? $form_value['SISTEM_REM'] : '')),
'sistem rem gas buang' => array(
'name' => 'SISTEM_REM_GAS_BUANG',
'size' => '30',
'value' => set_value('SISTEM_REM_GAS_BUANG', isset($form_value['SISTEM_REM_GAS_BUANG']) ? $form_value['SISTEM_REM_GAS_BUANG'] : '')),
'mesin transmisi' => array(
'name' => 'MESIN_TRANSMISI',
'size' => '30',
'value' => set_value('MESIN_TRANSMISI', isset($form_value['MESIN_TRANSMISI']) ? $form_value['MESIN_TRANSMISI'] : '')),
'lain lain' => array(
'name' => 'LAIN_LAIN',
'size' => '30',
'value' => set_value('LAIN_LAIN', isset($form_value['LAIN_LAIN']) ? $form_value['LAIN_LAIN'] : '')),
'lain lain2' => array(
'name' => 'LAIN_LAIN2',
'size' => '30',
'value' => set_value('LAIN_LAIN2', isset($form_value['LAIN_LAIN2']) ? $form_value['LAIN_LAIN2'] : '')),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Simpan'
)
);
?>
<h2><?php echo $breadcrumb ?></h2>
<!-- pesan start -->
<?php if (! empty($pesan)) : ?>
<div class="pesan">
<?php echo $pesan; ?>
</div>
<?php endif ?>
<!-- pesan end -->
<!-- form start -->
<?php echo form_open($form_action); ?>
<p>
<?php echo form_label('No Pengujian', 'NO_PENGUJIAN'); ?>
<?php echo form_input($form['no pengujian']); ?>
</p>
<?php echo form_error('NO_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Pemeriksaan', 'NO_PEMERIKSAAN'); ?>
<?php echo form_input($form['no pemeriksaan']); ?>
</p>
<?php echo form_error('NO_PEMERIKSAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Lokasi Pengujian', 'LOKASI_PENGUJIAN'); ?>
<?php echo form_input($form['lokasi pengujian']); ?>
</p>
<?php echo form_error('LOKASI_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Kode', 'NO_KODE'); ?>
<?php echo form_input($form['no kode']); ?>
</p>
<?php echo form_error('NO_KODE', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Kendaraan', 'NO_KENDARAAN'); ?>
<?php echo form_input($form['no kendaraan']); ?>
</p>
<?php echo form_error('NO_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Pemilik Kendaraan', 'PEMILIK_KENDARAAN'); ?>
<?php echo form_input($form['pemilik kendaraan']); ?>
</p>
<?php echo form_error('PEMILIK_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Type Merk Pabrik', 'TYPE_MERK_PABRIK'); ?>
<?php echo form_input($form['type merk pabrik']); ?>
</p>
<?php echo form_error('TYPE_MERK_PABRIK', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Jenis Kendaraan', 'JENIS_KENDARAAN'); ?>
<?php echo form_input($form['jenis kendaraan']); ?>
</p>
<?php echo form_error('JENIS_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Mulai Dipergunakan', 'MULAI_DIPERGUNAKAN'); ?>
<?php echo form_input($form['mulai dipergunakan']); ?>
</p>
<?php echo form_error('MULAI_DIPERGUNAKAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Laporan', 'NO_LAPORAN'); ?>
<?php echo form_input($form['no laporan']); ?>
</p>
<?php echo form_error('NO_LAPORAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Jenis Pemeriksaan', 'JENIS_PEMERIKSAAN'); ?>
<?php echo form_radio('JENIS_PEMERIKSAAN', 'Utama'); ?> Utama
<?php echo form_radio('JENIS_PEMERIKSAAN', 'Ulang'); ?> Ulang
</p>
<p>
<?php echo form_label('Jarak Pemakaian', 'JARAK_PEMAKAIAN'); ?>
<?php echo form_input($form['jarak pemakaian']); ?>
</p>
<?php echo form_error('JARAK_PEMAKAIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Berat Kendaraan', 'BERAT_KENDARAAN'); ?>
<?php echo form_input($form['berat kendaraan']); ?>
</p>
<?php echo form_error('BERAT_KENDARAAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_submit($form['submit']); ?>
<?php echo anchor('pengujian', 'Batal', array('class' => 'cancel')) ?>
</p>
<?php echo form_close(); ?>
<?php echo var_dump($form["no pengujian"]); ?>
and this
<?php
$form = array(
'no pengujian' => array(
'name' => 'NO_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PENGUJIAN', isset($form_value['NO_PENGUJIAN']) ? $form_value['NO_PENGUJIAN'] : '')),
'no chasis' => array(
'name' => 'NO_CHASIS',
'size' => '30',
'class' => 'radio',
'value' => set_value('NO_CHASIS', isset($_POST['NO_CHASIS']))),
'plat pabrik pembuat' => array(
'name' => 'PLAT_PABRIK_PEMBUAT',
'size' => '30',
'class' => 'radio',
'value' => set_value('PLAT_PABRIK_PEMBUAT', isset($_POST['PLAT_PABRIK_PEMBUAT']))),
'plat nomor' => array(
'name' => 'PLAT_NOMOR',
'size' => '30',
'class' => 'radio',
'value' => set_value('PLAT_NOMOR', isset($_POST['PLAT_NOMOR']))),
'tulisan' => array(
'name' => 'TULISAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('TULISAN', isset($_POST['TULISAN']))),
'penghapus kaca depan' => array(
'name' => 'PENGHAPUS_KACA_DEPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PENGHAPUS_KACA_DEPAN', isset($_POST['PENGHAPUS_KACA_DEPAN']))),
'klakson' => array(
'name' => 'KLAKSON',
'size' => '30',
'class' => 'radio',
'value' => set_value('KLAKSON', isset($_POST['KLAKSON']))),
'kaca spion' => array(
'name' => 'KACA_SPION',
'size' => '30',
'class' => 'radio',
'value' => set_value('KACA_SPION', isset($_POST['KACA_SPION']))),
'pandangan ke depan' => array(
'name' => 'PANDANGAN_KE_DEPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PANDANGAN_KE_DEPAN', isset($_POST['PANDANGAN_KE_DEPAN']))),
'kaca penahan sinar' => array(
'name' => 'KACA_PENAHAN_SINAR',
'size' => '30',
'class' => 'radio',
'value' => set_value('KACA_PENAHAN_SINAR', isset($_POST['KACA_PENAHAN_SINAR']))),
'alat pengendalian' => array(
'name' => 'ALAT_PENGENDALIAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('ALAT_PENGENDALIAN', isset($_POST['ALAT_PENGENDALIAN']))),
'lampu indikasi' => array(
'name' => 'LAMPU_INDIKASI',
'size' => '30',
'class' => 'radio',
'value' => set_value('LAMPU_INDIKASI', isset($_POST['LAMPU_INDIKASI']))),
'speedometer' => array(
'name' => 'SPEEDOMETER',
'size' => '30',
'class' => 'radio',
'value' => set_value('SPEEDOMETER', isset($_POST['SPEEDOMETER']))),
'perlengkapan' => array(
'name' => 'PERLENGKAPAN',
'size' => '30',
'class' => 'radio',
'value' => set_value('PERLENGKAPAN', isset($_POST['PERLENGKAPAN']))),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Simpan'
)
);
?>
<h2><?php echo $breadcrumb ?></h2>
<!-- pesan start -->
<?php if (! empty($pesan)) : ?>
<div class="pesan">
<?php echo $pesan; ?>
</div>
<?php endif ?>
<!-- pesan end -->
<!-- form start -->
<?php echo form_open($form_action); ?>
<p>
<?php echo form_label('No Pengujian', 'NO_PENGUJIAN'); ?>
<?php echo form_input($form['no pengujian']); ?>
</p>
<?php echo form_error('NO_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('No Chasis', 'NO_CHASIS'); ?>
<?php echo form_radio('NO_CHASIS', 'Lulus'); ?> Lulus
<?php echo form_radio('NO_CHASIS', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Plat Pabrik Pembuat', 'PLAT_PABRIK_PEMBUAT'); ?>
<?php echo form_radio('PLAT_PABRIK_PEMBUAT', 'Lulus'); ?> Lulus
<?php echo form_radio('PLAT_PABRIK_PEMBUAT', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Plat Nomor', 'PLAT_NOMOR'); ?>
<?php echo form_radio('PLAT_NOMOR', 'Lulus'); ?> Lulus
<?php echo form_radio('PLAT_NOMOR', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Tulisan', 'TULISAN'); ?>
<?php echo form_radio('TULISAN', 'Lulus'); ?> Lulus
<?php echo form_radio('TULISAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Penghapus Kaca Depan', 'PENGHAPUS_KACA_DEPAN'); ?>
<?php echo form_radio('PENGHAPUS_KACA_DEPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PENGHAPUS_KACA_DEPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Klakson', 'KLAKSON'); ?>
<?php echo form_radio('KLAKSON', 'Lulus'); ?> Lulus
<?php echo form_radio('KLAKSON', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Kaca Spion', 'KACA_SPION'); ?>
<?php echo form_radio('KACA_SPION', 'Lulus'); ?> Lulus
<?php echo form_radio('KACA_SPION', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Pandangan Ke Depan', 'PANDANGAN_KE_DEPAN'); ?>
<?php echo form_radio('PANDANGAN_KE_DEPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PANDANGAN_KE_DEPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Kaca Penahan Sinar', 'KACA_PENAHAN_SINAR'); ?>
<?php echo form_radio('KACA_PENAHAN_SINAR', 'Lulus'); ?> Lulus
<?php echo form_radio('KACA_PENAHAN_SINAR', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Alat Pengendalian', 'ALAT_PENGENDALIAN'); ?>
<?php echo form_radio('ALAT_PENGENDALIAN', 'Lulus'); ?> Lulus
<?php echo form_radio('ALAT_PENGENDALIAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Lampu Indikasi', 'LAMPU_INDIKASI'); ?>
<?php echo form_radio('LAMPU_INDIKASI', 'Lulus'); ?> Lulus
<?php echo form_radio('LAMPU_INDIKASI', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Speedometer', 'SPEEDOMETER'); ?>
<?php echo form_radio('SPEEDOMETER', 'Lulus'); ?> Lulus
<?php echo form_radio('SPEEDOMETER', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_label('Perlengkapan', 'PERLENGKAPAN'); ?>
<?php echo form_radio('PERLENGKAPAN', 'Lulus'); ?> Lulus
<?php echo form_radio('PERLENGKAPAN', 'Gagal'); ?> Gagal
</p>
<p>
<?php echo form_submit($form['submit']); ?>
<?php echo anchor('pengujian', 'Batal', array('class' => 'cancel')) ?>
</p>
<?php echo form_close(); ?>
and this is the trigger form php myadmin
CREATE TRIGGER `trigger_peralatan` BEFORE INSERT ON `peralatan`
FOR EACH ROW begin
if (new.NO_CHASIS = "Lulus"
AND new.PLAT_PABRIK_PEMBUAT = "Lulus"
AND new.PLAT_NOMOR = "Lulus"
AND new.TULISAN = "Lulus"
AND new.PENGHAPUS_KACA_DEPAN = "Lulus"
AND new.KLAKSON = "Lulus"
AND new.KACA_SPION = "Lulus"
AND new.PANDANGAN_KE_DEPAN = "Lulus"
AND new.KACA_PENAHAN_SINAR = "Lulus"
AND new.ALAT_PENGENDALIAN = "Lulus"
AND new.LAMPU_INDIKASI = "Lulus"
AND new.SPEEDOMETER = "Lulus"
AND new.PERLENGKAPAN = "Lulus")
then
UPDATE pengujian
SET PERALATAN = "Lulus"
WHERE NO_PENGUJIAN = new.NO_PENGUJIAN;
else
UPDATE pengujian
SET PERALATAN = "Gagal"
WHERE NO_PENGUJIAN = new.NO_PENGUJIAN; end if;
end
and this for the last trigger
CREATE TRIGGER `trigger_nilai` BEFORE INSERT ON `pengujian`
FOR EACH ROW begin
if
(new.AS_DAN_SUSPENSI = "Lulus" AND
new.BAN_DAN_PELEK = "Lulus" AND
new.LAIN_LAIN = "Lulus" AND
new.LAIN_LAIN2 = "Lulus" AND
new.MESIN_TRANSMISI = "Lulus" AND
new.PERALATAN = "Lulus" AND
new.RANGKA_DAN_BODI = "Lulus" AND
new.SISTEM_KEMUDI = "Lulus" AND
new.SISTEM_PENERANGAN = "Lulus" AND
new.SISTEM_REM = "Lulus" AND
new.SISTEM_REM_GAS_BUANG = "Lulus")
then
SET new.PENILAIAN = "Lulus" ;
else
SET new.PENILAIAN = "Gagal" ; end if;
end
this is the insert query
INSERT INTO `pengujian`(`NO_PENGUJIAN`, `NO_PEMERIKSAAN`, `LOKASI_PENGUJIAN`, `NO_KODE`, `NO_KENDARAAN`, `PEMILIK_KENDARAAN`, `TYPE_MERK_PABRIK`, `JENIS_KENDARAAN`, `MULAI_DIPERGUNAKAN`, `TANGGAL_PEMERIKSAAN`, `NO_LAPORAN`, `JENIS_PEMERIKSAAN`, `JARAK_PEMAKAIAN`, `BERAT_KENDARAAN`, `PERALATAN`, `SISTEM_PENERANGAN`, `SISTEM_KEMUDI`, `AS_DAN_SUSPENSI`, `BAN_DAN_PELEK`, `RANGKA_DAN_BODI`, `SISTEM_REM`, `SISTEM_REM_GAS_BUANG`, `MESIN_TRANSMISI`, `LAIN_LAIN`, `LAIN_LAIN2`, `PENILAIAN`, `TANGGAL_PEMERIKSAAN_BERIKUTNYA`, `CATATAN`, `PENGUJI`, `BIAYA_TOTAL`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10],[value-11],[value-12],[value-13],[value-14],[value-15],[value-16],[value-17],[value-18],[value-19],[value-20],[value-21],[value-22],[value-23],[value-24],[value-25],[value-26],[value-27],[value-28],[value-29],[value-30])
It's a little confusing...

Related

put spans and divs around paginate_links

I wanna style my links and in order to do that I need some spans and divs around it but I dunno how it's done when using paginate_links() from WordPress.
Can you help me to do that?
<div class="pagination">
<?php echo
$pagination = paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('← Previous'),
'next_text' => __('Next →'),
'total' => ceil($total / $items_per_page),
'current' => $page,
'type' => 'plain'
));
?>
</div>
so far it looks like that
Just change li to div / span whatever. The main difference is to change your "type" from "plain" to "array" and then you can do what you want with it.
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
$prev_next = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_text' => __('← Previous'),
'next_text' => __('Next →')
) );
if($prev_next){ ?>
<ul>
<?php
foreach($prev_next as $key=>$val){
if (strpos($val,"'page-numbers current'") !== false) {
echo '<li class="active item">'.$val.'</li>';
} elseif (strpos($val,'"next page-numbers"') !== false || strpos($val,'"prev page-numbers"') !== false ) {
echo'<li>'.$val.'</li>';
} else {
echo '<li class="item">'.$val.'</li>';
}
} ?>
</ul>
<?php } ?>

yii2 - multiple rows load into same table from one form

I am trying to save a schedule of working days on a table multiple rows at once...
I am doing this wrong, still giving me errors.
I have seen tabular inputs from others, but can't get this right.
I really need some other eyes on it.
I have a similar problem as https://phppedia.com/en/knowledge-base/32481399/yii2-insert-multiple-records-of-a-same-table
model:
public
function rules()
{
return [
['store_id', 'string'],
['day', 'string'],
['start_hour', 'string'],
['end_hour', 'string'],
['holiday','boolean'],
];
}
controler:
public function actionCreate()
{
$count = count(Yii::$app->request->post('Openhour', []));
$model = [new Openhours()];
for ($i = 1; $i < $count; $i++) {
$model[] = new Openhours();
}
if ($model->loadMultiple($model, Yii::$app->request->post())) {
foreach ($model as $model) {
$model->save(false);
}
}
return $this->render('create', ['model' => $model,]);
}
_form
<?php $stores = Stores::getAll() ?>
<?php foreach ($stores as $store): ?>
<?php if ($store->id !== 0): ?>
<?php $listData[$store->id] = [$store->id => $store->title]; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'options' => ['class' => 'model-form'],]); ?>
<?php foreach ($model as $index => $model): ?>
<div class="row row-cols-3">
<div class="col">
<h5>
<?php if ($store->title === Yii::$app->user->identity->username) : ?>
<?= $form->field($model, '[$index]store_id')->hiddenInput(['value' => $store->title])->label($store->title) ?>
<?php else: ?>
<?= $form->field($model, '[$index]store_id')->dropDownList($listData, ['prompt' => 'Select...']); ?>
<?php endif; ?>
</h5>
</div>
<div class="col">Opening</div>
<div class="col">Close</div>
</div>
<?php $days = Storedays::getAll() ?>
<?php foreach ($days as $day): ?>
<div class="row row-cols-3">
<div class="col">
<div class="row justify-content-between">
<div class="col">
<h6><?= $day->name ?></h6>
<?= $form->field($model, '[$index]day')->hiddenInput(['value' => $day->name, 'id' => 'day' . $day->id])->label(false) ?>
</div>
<div class="col">
<?= $form->field($model, '[$index]holiday')->checkbox(['selected' => $model->holiday, 'id' => 'holiday' . $day->id])->label(false) ?>
</div>
</div>
</div>
<div class="col">
<?= $form->field($model, '[$index]start_hour')->Input('text')->widget(TimePicker::class, ['options' => ['id' => 'start_hour' . $day->id], 'pluginOptions' => ['maxHours' => '8', 'template' => 'dropdown', 'showSeconds' => false, 'showMeridian' => false, 'minuteStep' => 15,]])->label(false) ?>
</div>
<div class="col">
<?= $form->field($model, '[$index]end_hour')->Input('text')->widget(TimePicker::class, ['options' => ['id' => 'end_hour' . $day->id], 'pluginOptions' => ['maxHours' => '8', 'template' => 'dropdown', 'showSeconds' => false, 'showMeridian' => false, 'minuteStep' => 15,]])->label(false) ?>
</div>
</div>
<?php endforeach; ?>
<?php if (IS_ROOT) : ?><?= $form->field($model, '[$index]slug') ?><?php endif; ?>
<?= Html::submitButton('save', ['class' => 'btn btn-primary']) ?>
<hr class="mb-3">
<?php endforeach; ?>
<?php ActiveForm::end(); ?>
First you have an array of objects and you must use plural name instead.
So model become models.
Second you must use functions for loading multiple models from request Model::loadMultiple($models) and for validate multiple models Model::validateMultiple($models).
Now in your controller:
public function actionCreate()
{
$count = count(Yii::$app->request->post('Openhour', []));
$models = [new Openhours()];
for ($i = 1; $i < $count; $i++) {
$models[] = new Openhours();
}
if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) {
foreach ($models as $model) {
$model->save(false);
}
}
return $this->render('create', ['models' => $models]);
}
Now in your _form.php change the line:
<?php foreach ($model as $index => $model): ?>
To:
<?php foreach ($models as $index => $model): ?>

Catch button in controller

I have this form in view
<?php
$form = ActiveForm::begin();
$items = [201 => 'Тест', 202 => 'Тест2'];
echo Html::dropDownList('list', 'null', $items);
?>
<div class="form-group">
<?=
Html::submitButton(
'Удалить отмеченные',[
'data' => ['confirm' => 'Вы действительно хотите перенести отмеченные товары в выбранную категорию?'],
'name' => 'deleteProduct',
'value' => 'delProduct', // добавить value
'class' => 'btn btn-danger'
])
?>
</div>
<?php ActiveForm::end(); ?>
And this in controller
if (Yii::$app->request->post('deleteProduct'))
{
$lk_number = $_POST['list'];
print_r($lk_number);exit();
}
But when click on button there is no catch in controller. What I do wrong?

Insert multiple records of a same table Yii2

I want to insert same record in one table. I have only one input array in the below form but i want to save multiple time record for label input array.
my form is
<div class="surveys-questions-form">
<?php $form = ActiveForm::begin(); ?>
<?php
if(isset($_GET['option_id']) and $_GET['option_id'] > 0)
$id= $_GET['option_id'];
else
$id= $model->option_id;
echo $form->field($model, 'question_id')->hiddenInput(['value' => $id])->label(false);
?>
<div class="col-md-6">
<div id="question_wrapper">
<?= $form->field($model, 'type')->dropDownList([ 'text' => 'Text', 'numbers' => 'Numbers', 'date' => 'Date', 'texarea' => 'Texarea', 'checkbox' => 'Checkbox', 'radio' => 'Radio', 'rating' => 'Rating', ], ['prompt' => '']) ?>
<div id="add_more_field">
<?= $form->field($model, 'label[]')->textInput(['maxlength' => true]) ?>
</div>
<div class="form-group">
<?php
echo Html::a('Add more', 'javascript:void(0);', [
'id' => 'surveys-questions-new-button',
'class' => 'pull-right btn btn-primary btn-xs'
])
?>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
and controller
public function actionCreate()
{
$model = new QuestionsOptions();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->option_id]);
} else {
return $this->renderAjax('create', [
'model' => $model,
]);
}
}
Give me the following error when i try to submit form.
Label must be a string.
My $_POST array
Array
(
[_csrf-backend] => LXBhajI3YVpOIikeRWYHYkNCAD4Kb1ZrQzwER21GL2MdCTgkWm5ZDQ==
[QuestionsOptions] => Array
(
[question_id] => 47
[type] => numbers
[label] => Array
(
[0] => Label1
[1] => Label2
[2] => Labe3
)
)
)
If you want to save multiple record use loop i suggest you to use foreach loop it is best
public function actionCreate()
{
$model = new QuestionsOptions();
if ($model->load(Yii::$app->request->post())) {
if(sizeof(array_filter($_POST['QuestionsOptions']['label'])) > 0){
foreach($_POST['QuestionsOptions']['label'] as $key => $row){
$model->setIsNewRecord(true);
$model->id = null;
$model->label = $row;
$model->save();
}
}
return $this->redirect(['view', 'id' => $model->option_id]);
} else {
return $this->renderAjax('create', [
'model' => $model,
]);
}
}

cakephp instead of user_id how do I get for instance username in the view

I have 3 tables: users, comments and videos.
In my videos view.ctp I can't get the username displayed, only the user_id.
I can't figure it out, can someone point me in the right direction?
User model:
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'user_id',
'dependent' => false
),
}
Video model:
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'video_id',
'dependent' => false
),
}
Comment model:
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id'
),
'Video' => array(
'className' => 'Video',
'foreignKey' => 'video_id'
)
);
}
Videos view.ctp
<?php if (!empty($video['Comment'])): ?>
<?php foreach ($video['Comment'] as $comment): ?>
<p><?php echo $comment['comment_created']; ?></p>
<p><?php echo $comment['User']['user_username']; ?></p>
<p><?php echo $comment['user_id']; ?></p>
<p><?php echo $comment['comment_body']; ?></p>
<?php endforeach; ?>
<?php endif; ?>
VideosController
public function view($id = null) {
$this->loadModel('Comment');
if (!$this->Video->exists($id)) {
throw new NotFoundException(__('Invalid video'));
}
$options = array('conditions' => array('Video.' . $this->Video->primaryKey => $id));
$this->set('video', $this->Video->find('first', $options));
$current_user = $this->Auth->user('user_id');
if ($this->request->is('post')) {
$this->Comment->create();
/*save the current's user id in database*/
$this->Comment->set('user_id', $current_user);
/*save the current's video id in database*/
$this->Comment->set('video_id', $id);
if ($this->Comment->save($this->request->data)) {
$this->Session->setFlash(__('You\'re comment has been placed.'));
return $this->redirect(array('action' => 'view/' . $id));
} else {
$this->Session->setFlash(__('You\'re comment could not be placed. Please, try again.'));
}
}
$this->set(compact('users', 'videos'));
}
Solution:
In the controller:
$comments = $this->Video->Comment->find('all', array('conditions' => array('Comment.video_id' => $id)));
In the view:
<?php foreach ($comments as $comment): ?>
<p><?php echo $comment['User']['user_username']; ?></p>
<p><?php echo $comment['Comment']['comment_created']; ?></p>
<p><?php echo $comment['Comment']['comment_body']; ?></p>
<?php endforeach; ?>