I am trying to set a form validation rule. It says Unable to access an error message corresponding to your field name Customer (validate_customer). Any help on that would be appreciated.
$this->form_validation->set_rules('customer_id', 'Customer' ,'required|callback_validate_customer');
And this is my validation methond.
function validate_customer() {
if((double)$this->input->post('paid_amount') == 0)
{
$this->form_validation->set_message('validate_customer' , 'Can not sale.');
return FALSE;
} else {
return TRUE;
}
}
CodePudding user response:
These methods are set_message
, form_validation
and callback_
no more in Codeigniter 4. For this, you need to use a custom rule.
Example:
<?php
namespace App\Validation;
class CustomRules{
public function customerValidation( ... , array $data)){
}
}
And use it like
"customer_id" => "required|customerValidation[customer_id]"
Check these
CodePudding user response:
Finally this code works for me.
$this->form_validation->set_rules(
'customer_id', 'Customer',
'required|min_length[1]|max_length[12]|customer_due_check',
array(
'required' => 'You have not provided %s.',
'customer_due_check' => 'This %s already exists.'
)
);