Advertisement
Guest User

Untitled

a guest
Apr 8th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1.     <?php
  2.     require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php');
  3.  
  4.     error_reporting(-1);
  5.     ini_set('display_errors', 1);
  6.     class Testas extends CI_controller {
  7.  
  8.         public function __construct()
  9.         {
  10.             parent::__construct();
  11.         }
  12.  
  13.         public function index()
  14.         {
  15.             $this->load->module_language('fuel', 'fuel');
  16.             $this->load->library('form_builder');
  17.             $this->load->library('validator');
  18.            
  19.             $fields['email'] = array('type' => 'email', 'label'=>'Email', 'required' => TRUE);
  20.             $fields['name'] = array('type' => '','label'=>'Your name');
  21.             $this->form_builder->set_fields($fields);
  22.            
  23.             $validator = $this->form_builder->get_validator();
  24.            
  25.             //var_dump($validator);exit; //If I uncomment it, it echoes NULL
  26.            
  27.             $validator->add_rule('name', 'required', "This is required", array($this->input->post('name')));
  28.            
  29.             if (!empty($_POST))
  30.             {
  31.                 if ($validator->is_valid())
  32.                 {
  33.                     echo "validation succeeded";
  34.                
  35.                 }
  36.                 else
  37.                 {
  38.                     echo "validation failed";
  39.                 }
  40.             }
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement