My Form validation code.
<?php
/**
Form Validation
*/
class Form{
public $currentValue;
public $values = array();
public $errors = array();public function __construct(){}
public function post($key){
$this->valuse[$key] = trim($_POST[$key]); $this->currentValue = $key; return $this;
}
public function isEmpty(){
if(empty($this->valuse[$this->currentValue])){ $this->errors[$this->currentValue]['empty'] = "Field must be empty"; } return $this;
}
public function isCatEmpty(){
if($this->valuse[$this->currentValue] == 0){ $this->errors[$this->currentValue]['empty'] = "Field must be empty"; } return $this;
}
public function length($min=0, $max){
if (strlen($this->valuse[$this->currentValue]) < $min OR strlen($this->valuse[$this->currentValue]) > $max) { $this->errors[$this->currentValue]['length'] = "Should Min ".$min." And Max " .$max. "Characters."; } return $this;
}
public function submit(){
if(empty($this->errors)){ return true; }else{ return false; }
}
}
I don't found this problem.
My Category insert Code is
public function insertCategory(){
if(!($_POST)){
header("Location:".BASE_URL."/Admin/addCategory";
}
$input = $this->load->validation("Form";
$input->post('name'
->isEmpty();
$input->post('title'
->isEmpty();
if ($input->submit()) {
$tablePost = "category";
$name = $input->values['name'];
$title = $input->values['title'];
$data = array(
'name' => $name,
'title' => $title
);
$catModel = $this->load->model("CatModel");
$result = $catModel->insertCat($tableCat, $data);
$mdata = array();
if ($result == 1) {
$mdata['msg'] = "Category Added Successfully.";
} else {
$mdata['msg'] = "Category Not Added Successfully.";
}
$url = BASE_URL."/Admin/categoryList?msg=".urlencode(serialize($mdata));
header("Location:$url");
} else {
$data["postErrors"] = $input->errors;
$tableCat = "category";
$this->load->view("admin/header");
$this->load->view("admin/sidebar");
$catModel = $this->load->model("CatModel");
$data['catlist'] = $catModel->catList($tableCat);
$this->load->view("admin/addcategory", $data);
$this->load->view("admin/footer");
}
}
this is data not inserted.
I don't understand why this problem.
post("name"
why post() method value don't work.
this line work not properly.
$name = $input->values['name'];
$title = $input->values['title'];
?>