Advertisement
cdsatrian

caontoh validasi form CI

Jun 25th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. //--filename: views/myform.php
  2. <!DOCTYPE html>
  3. <html>
  4.     <head>
  5.         <meta charset='utf-8'/>
  6.         <title>Simple Validation</title>
  7.     </head>
  8.     <body>
  9.       <?php echo validation_errors(); ?>
  10.       <?php echo form_open('form'); ?>
  11.         <label>tagihan anda<label>
  12.         <input type='text' name='tagihan' id='tagihan' value='<?php echo set_value('tagihan'); ?>'/><br />
  13.         <label>bayar tagihana<label>
  14.         <input type='text' name='bayar' id='bayar' value='<?php echo set_value('bayar'); ?>'/><br />
  15.         <input type='submit' value='submit'/>
  16.       </form>
  17.     </body>
  18. </html>
  19.  
  20. //--filename: views/formsuccess.php
  21. <html>
  22. <head>
  23. <title>My Form</title>
  24. </head>
  25. <body>
  26. <h3>Your form was successfully submitted!</h3>
  27. <p><?php echo anchor('form', 'Try it again!'); ?></p>
  28. </body>
  29. </html>
  30.  
  31. //--filename: controller/form.php
  32. <?php
  33. class Form extends CI_Controller {
  34.     function index()
  35.     {
  36.         $this->load->helper(array('form', 'url'));
  37.         $this->load->library('form_validation');
  38.         $this->form_validation->set_rules('bayar', 'Bayar', 'required|less_than['. $this->input->post('tagihan').']');     
  39.         if ($this->form_validation->run() == FALSE)
  40.         {
  41.             $this->load->view('myform');
  42.         }
  43.         else
  44.         {
  45.             $this->load->view('formsuccess');
  46.         }
  47.     }
  48. }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement