Hey guys,for a couple days, i have try to make form validation using php mvc base structure, and i have try to following this tutorial on youtube : [youtube]rWon2iC-cQ0[/youtube] but, on that tutorial.. in action line.. is just redirect on that page it self. bcz the validate checking function is write in sama page with the form. bcz i have my own mvc, i try to put in different location and i separate it into 3 files : view : index.php controller : register.php model : register_model.php libs : validate.php view/index.php <form method="post" action="<?php echo URL; ?>register/insert"> <table> <tr> <td>username</td> <td><input name="username" type="text" autocomplete="off" value="<?php echo Register_Model::get('username'); ?>" /></td> <td></td> </tr> <tr> <td>first name</td> <td><input name="first_name" type="text" autocomplete="off" value="<?php echo Register_Model::get('first_name'); ?>" /></td> <td></td> </tr> <tr> <td>last name</td> <td><input name="last_name" type="text" autocomplete="off" value="<?php echo Register_Model::get('last_name'); ?>" /></td> <td></td> </tr> <tr> <td>password</td> <td><input name="password" type="text" /></td> <td></td> </tr> <tr> <td>retype password</td> <td><input name="retype_password" type="text" /></td> <td></td> </tr> <tr> <td>address</td> <td><textarea name="address" placeholder="your address here"><?php echo Register_Model::get('address'); ?></textarea></td> <td></td> </tr> <tr> <td>phone</td> <td><input name="phone" type="text" autocomplete="off" value="<?php echo Register_Model::get('phone'); ?>" /></td> <td></td> </tr> <tr> <td>No KTP</td> <td><input name="nik_numb" type="text" autocomplete="off" value="<?php echo Register_Model::get('nik_numb'); ?>" /></td> <td></td> </tr> <tr> <td>gender</td> <td> <select name="gender"> <option value="male">male</option> <option value="female">female</option> </select> </td> <td></td> </tr> <tr> <td>role</td> <td> <select name="role"> <option value="member">member</option> <option value="operator">operator</option> <option value="administrator">administrator</option> </select> </td> <td></td> </tr> <tr> <td><input type="submit" /></td> <td> </td> <td> </td> </tr> </table> </form> controllers/register.php public function insert(){ if(Register_Model::val()){ $validate = new Validate(); $validation = $validate->check($_POST, array( 'username' => array( 'required' => true, 'min' => 5, 'max' => 12, 'unique' => 'users' ), 'first_name' => array( 'required' => true, 'min' => 5, 'max' => 12 ), 'last_name' => array( 'required' => true, 'min' => 5, 'max' => 12 ), 'password' => array( 'required' => true, 'min' => 6 ), 'retype_password' => array( 'required' => true, 'matches' => 'password' ), 'address' => array( 'required' => true ), 'phone' => array( 'required' => true ), 'nik_numb' => array( 'required' => true ), 'gender' => array( 'required' => true ), 'role' => array( 'required' => true ) )); if($validation->passed()){ //register user $c = $this->model->numbering(); foreach ($c as $key => $value) { $data = $value['id']; } $abc['member_id'] = 0 . date('ymdN') . '00' . $data+1; $abc['username'] = $_POST['username']; $abc['name'] = $_POST['first_name'] ."_". $_POST['last_name']; $abc['last_name'] = $_POST['last_name']; $abc['password'] = $_POST['password']; $abc['address'] = $_POST['address']; $abc['phone'] = $_POST['username']; $abc['nik_numb'] = $_POST['nik_numb']; $abc['gender'] = $_POST['gender']; $abc['role'] = $_POST['role']; $this->model->create($abc); }else{ //output errors echo 'inserting data failed'; print_r($validation->errors()); } header('location:'.URL.'register'); } } and for the model page, is : public function numbering(){ $sth = $this->db->prepare('SELECT * FROM member_data'); $sth->execute(); return $sth->fetchAll(); } public static function val($type = 'post'){ switch($type){ case 'post' : return (!empty($_POST)) ? true : false; break; case 'get' : return (!empty($_GET)) ? true : false; break; default : return false; break; } } public static function get($item){ if(isset($_POST[$item])){ return $_POST[$item]; }else if(isset($_GET[$item])){ return $_GET[$item]; } return ''; } public function create($abc){ $insert = $this->db->prepare('INSERT INTO member_data (`member_id`,`username`,`name`, `password`,`address`,`phone`,`nik_numb`,`gender`,`role`) VALUESmember_id, :username, :name, assword, :address, hone, :nik_numb, :gender, :role) '); $insert->execute(array( ':member_id' => $abc['member_id'], ':username' => $abc['username'], ':name' => $abc['name'], 'assword' => $abc['password'], ':address' => $abc['address'], 'hone' => $abc['phone'], ':nik_numb' => $abc['nik_numb'], ':gender' => $abc['gender'], ':role' => $abc['role'] )); } and last for libs, the code like this below: <?php class Validate{ private $_passed = false, $_errors = array(), $db = null; public function __construct(){ $this->db = new Database(); } public function check($source, $items = array()){ foreach($items as $item => $rules){ foreach($rules as $rule => $rule_value){ $value = trim($source[$item]); $item = escapeshellcmd($item); if($rule === 'required' && empty($value)){ $this->addError("{$item} is required"); }else{ switch($rule){ case 'min': if(strlen($value) < $rule_value){ $this->addError("{$item} must be a minimum of {$rule_value}"); } break; case 'max': if(strlen($value) > $rule_value){ $this->addError("{$item} must be a maximum of {$rule_value}"); } break; case 'matches': if($value != $source[$rule_value]){ $this->addError("{$rule_value} must matches"); } break; case 'unique': $check = $this->db->prepare($rule_value, array($item, '=' ,$value)); //if($check->count()){ // $this->addError("{$item} already exists"); //} break; } } } } if(empty($this->_errors)){ $this->_passed = true; } return $this; } public function addError($error){ $this->_errors[] = $error; } public function errors(){ $this->_errors = $this->view->err; return $this->_errors; } public function passed(){ return $this->_passed; } } and the question is, how i called and show validate error message on view index file? ( on red color )