Cara membuat form validation
*Catatan
Menggunakan bahasa indonesia
$this->form_validation->set_rules('password','Password','required',[
'required' => 'Password wajib diisi !'
]);
Controller/form
<?php
class Form extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->library('form_validation');
}
function index(){
$this->load->view('v_form');
}
function aksi(){
$this->form_validation->set_rules('nama','Nama','required');
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('konfir_email','Konfirmasi Email','required');
if($this->form_validation->run() != false){
echo "Form validation oke";
}else{
$this->load->view('v_form');
}
}
}
View/v_form
<!DOCTYPE html>
<html>
<head>
<title>Membuat form validation dengan Codeigniter | sobatjagoan.com</title>
</head>
<body>
<h1>Membuat Form Validation dengan CodeIgniter</h1>
<?php echo validation_errors(); ?>
<?php echo form_open('form/aksi'); ?>
<label>Nama</label><br/>
<input type="text" name="nama"><br/>
<?php echo form_error('nama'); ?>
<label>Email</label><br/>
<input type="text" name="email"><br/>
<?php echo form_error('email','<div class="text-danger small ml-2">','</div'); ?>
<label>Konfirmasi Email</label><br/>
<input type="text" name="konfir_email"><br/>
<input type="submit" value="Simpan">
</form>
</body>
</html>
Download File Codeigniter dan form_validation
https://drive.google.com/drive/folders/1tDBE0t3bjr26iWaTKwVg1jzSNobGVOYr?usp=sharing
Sumber :
Contoh yang sudah jadi di CI dan Bootstap
https://drive.google.com/drive/folders/193_U_B3_lC6zSV_CPch_jRX2eMkovg4U?usp=sharing
No comments