7.Cara Membuat Form Validation

File yang sudah jadi : https://drive.google.com/drive/folders/18qJ9YPpxMjS0doJ9-pyMJk8l7qa6OEzZ?usp=sharing

autoload: form_validation dan url

Config : nama alamat url


controller/welcome

<?php

defined('BASEPATH') OR exit('No direct script access allowed');


class Welcome extends CI_Controller {


public function index()

{

$this->load->view('welcome_message');

}

public function aksi()

{

$this->form_validation->set_rules('nama','Nama','required',['required'=>'Nama Belum Terisi']);

$this->form_validation->set_rules('alamat','Alamat','required',['required'=>'Alamat Belum Terisi']);

if($this->form_validation->run()!=false)

{

echo "Data Sudah terisi";

}else{

$this->load->view('welcome_message');

}

}

}



View/welcome

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>Cara membuat form validation</title>

<style type="text/css">

</style>
</head>
<body>

<div id="container">
<h1 style="text-align:center;margin-top:5%;">Cara membuat form validation</h1>

<form method="post" action="<?php echo site_url('welcome/aksi')?>" class="mt-5" style="margin-left:30%;">
<div class="form-group">
<label>Nama</label>
<input type="text" class="form-control" name="nama" style="width:50%;" placeholder="Masukan Nama Anda">
<?php echo form_error('nama','<div class="text-danger small">','</div>');?>
</div>
<div class="form-group">
<label>Alamat</label>
<input type="text" class="form-control" name="alamat" style="width:50%;" placeholder="Masukan Alamat Anda">
<?php echo form_error('alamat','<div class="text-danger small">','</div>');?>
</div>
<div class="form-group">
<label>Jenis Kelamin</label>
<select name="jenkel" class="form-select" style="width:50%;">
<option>Laki-laki</option>
<option>Perempuan</option>
</select>
</div>
<button class="btn btn-primary mt-3">Simpan</button>
</form>
</div>

</body>
</html>




7.Cara Membuat Form Validation 7.Cara Membuat Form Validation Reviewed by Leo on 07:14 Rating: 5

No comments