Welcome Guest, Not a member yet? Register   Sign In
validation error
#1

(This post was last modified: 02-02-2023, 12:16 PM by devo.)

I encountered a confusing validation error,
so i try validation in model but i confusing about the error this is the error

my model validation : 
PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
AdministratorModel extends Model
{
protected 
$DBGroup          'default';
protected 
$table            'administrators';
protected 
$primaryKey      'id';
protected 
$useAutoIncrement true;
protected 
$insertID        0;
protected 
$returnType      'array';
protected 
$useSoftDeletes  true;
protected 
$protectFields    true;
protected 
$allowedFields    = [
'full_name','username','email',
'password'
];

// Validation
protected $validationRules = [
'full_name'    => ['label' => 'Full name''rules' => 'required|alpha_numeric_space'],
'username'    => ['label' => 'Username''rules' => 'required|alpha_numeric|min_length[2]|is_unique[administrators.username]'],
'email'        => ['label' => 'Email''rules' => 'required|valid_email|is_unique[administrators.email]'],
'password'    => ['label' => 'Password''rules' => 'required|min_length[6]'],
'pass_con' => ['label' => 'Password Confirmation''rules' => 'required'],
];
protected 
$validationMessages  = [];
protected 
$skipValidation      false;
protected 
$cleanValidationRules true;

public function 
_values()
{
return [
'full_name' => _post('full_name'),
'username' => _post('username'),
'email' => _post('email'),
'password' => _post('password')
];
}

public function 
store()
{
$req $this->_values();
$this->insert($req);
}



my controller method
PHP Code:
    /**
     * Create a new resource object, from "posted" parameters
     *
     * @return mixed
     */
    
public function create()
    {
        
$ins $this->model->store();
        
$validation $this->model->errors();

        echo 
'<h1>incoming request :</h1> <br>';
        echo 
'<pre>';
        
print_r(_post());
        echo 
'</pre>';
        if (
$validation) {
            echo 
'<h1>validation error :</h1> <br>';
            echo 
'<pre>';
            
print_r($validation);
            echo 
'</pre>';
        } else {
            echo 
$this->model->getInsertID();
        }
    } 

my view :

Code:
<?= form_open(route_to('administrator_create')); ?>
          <div class="form-group">
            <label for="full_name">Full name</label>
            <input type="text" class="form-control full_name" name="full_name" id="full_name" placeholder="Full name">
          </div>

          <div class="form-group">
            <label for="username">Username</label>
            <input type="text" class="form-control username" name="username" id="username" placeholder="Username" >
          </div>

          <div class="form-group">
            <label for="email">Email</label>
            <input type="email" class="form-control email" name="email" id="email" placeholder="Email" >
          </div>

          <div class="form-group">
            <label for="password">Password</label>
            <input type="password" class="form-control password" name="password" id="password" placeholder="Password" >
          </div>

          <div class="form-group">
            <label for="pass_con">Re-type Password</label>
            <input type="password" class="form-control pass_con" name="pass_con" id="pass_con" placeholder="Re-type Password">
          </div>

          <button type="submit" class="btn btn-primary px-5">Submit</button>
        <?= form_close() ?>
Reply
#2

you don't pass pass_con in _values() method.
Reply
#3

(02-02-2023, 03:09 PM)iRedds Wrote: you don't pass pass_con in _values() method.

ahh,, i miss it thank you
Reply




Theme © iAndrew 2016 - Forum software by © MyBB