General discussion
PHP form validation MVC form model doesn't work need to help

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"smile;
}
$input = $this->load->validation("Form"smile;
$input->post('name'smile
->isEmpty();

$input->post('title'smile
->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"smile
why post() method value don't work.
this line work not properly.
$name = $input->values['name'];
$title = $input->values['title'];

?>

My Form validation code. &lt;?php /** * Form Validation */ class Form{ public $currentValue; public $values = array(); public $errors = array(); public function __construct(){} public function post($key){ $this-&gt;valuse[$key] = trim($_POST[$key]); $this-&gt;currentValue = $key; return $this; } public function isEmpty(){ if(empty($this-&gt;valuse[$this-&gt;currentValue])){ $this-&gt;errors[$this-&gt;currentValue][&#039;empty&#039;] = &quot;Field must be empty&quot;; } return $this; } public function isCatEmpty(){ if($this-&gt;valuse[$this-&gt;currentValue] == 0){ $this-&gt;errors[$this-&gt;currentValue][&#039;empty&#039;] = &quot;Field must be empty&quot;; } return $this; } public function length($min=0, $max){ if (strlen($this-&gt;valuse[$this-&gt;currentValue]) &lt; $min OR strlen($this-&gt;valuse[$this-&gt;currentValue]) &gt; $max) { $this-&gt;errors[$this-&gt;currentValue][&#039;length&#039;] = &quot;Should Min &quot;.$min.&quot; And Max &quot; .$max. &quot;Characters.&quot;; } return $this; } public function submit(){ if(empty($this-&gt;errors)){ return true; }else{ return false; } } } I don&#039;t found this problem. My Category insert Code is public function insertCategory(){ if(!($_POST)){ header(&quot;Location:&quot;.BASE_URL.&quot;/Admin/addCategory&quot;); } **$input = $this-&gt;load-&gt;validation(&quot;Form&quot;); $input-&gt;post(&#039;name&#039;) -&gt;isEmpty(); ** $input-&gt;post(&#039;title&#039;) -&gt;isEmpty(); if ($input-&gt;submit()) { $tablePost = &quot;category&quot;; $name = $input-&gt;values[&#039;name&#039;]; $title = $input-&gt;values[&#039;title&#039;]; $data = array( &#039;name&#039; =&gt; $name, &#039;title&#039; =&gt; $title ); $catModel = $this-&gt;load-&gt;model(&quot;CatModel&quot;); $result = $catModel-&gt;insertCat($tableCat, $data); $mdata = array(); if ($result == 1) { $mdata[&#039;msg&#039;] = &quot;Category Added Successfully.&quot;; } else { $mdata[&#039;msg&#039;] = &quot;Category Not Added Successfully.&quot;; } $url = BASE_URL.&quot;/Admin/categoryList?msg=&quot;.urlencode(serialize($mdata)); header(&quot;Location:$url&quot;); } else { $data[&quot;postErrors&quot;] = $input-&gt;errors; $tableCat = &quot;category&quot;; $this-&gt;load-&gt;view(&quot;admin/header&quot;); $this-&gt;load-&gt;view(&quot;admin/sidebar&quot;); $catModel = $this-&gt;load-&gt;model(&quot;CatModel&quot;); $data[&#039;catlist&#039;] = $catModel-&gt;catList($tableCat); $this-&gt;load-&gt;view(&quot;admin/addcategory&quot;, $data); $this-&gt;load-&gt;view(&quot;admin/footer&quot;); } } this is data not inserted. I don&#039;t understand why this problem. post(&quot;name&quot;) why post() method value don&#039;t work. this line work not properly. **$name = $input-&gt;values[&#039;name&#039;]; $title = $input-&gt;values[&#039;title&#039;];** ?&gt;
edited Jul 4 at 10:30 pm
36
0
0
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft