我正在嘗試設定表單驗證規則。它說無法訪問與您的欄位名稱 Customer (validate_customer) 相對應的錯誤訊息。對此的任何幫助將不勝感激。
$this->form_validation->set_rules('customer_id', 'Customer' ,'required|callback_validate_customer');
這是我的驗證方法。
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;
}
}
uj5u.com熱心網友回復:
這些方法set_message,form_validation并callback_在笨4.沒有更多的對于這一點,你需要使用一個自定義規則。
例子:
<?php
namespace App\Validation;
class CustomRules{
public function customerValidation( ... , array $data)){
}
}
并像使用它一樣
"customer_id" => "required|customerValidation[customer_id]"
檢查這些
- 創建自定義規則
- 如何在 CodeIgniter 4 中創建自定義驗證規則
uj5u.com熱心網友回復:
最后這段代碼對我有用。
$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.'
)
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/371685.html
