Codeigniter表单验证规则一个字段应该大于其他
问题描述:
我需要确保amount
字段大于amount_left
字段。Codeigniter表单验证规则一个字段应该大于其他
$config=array(
array(
'field' => 'amount',
'label' => 'actual amount',
'rules' => 'trim|required'
),
array(
'field' => 'amount_left',
'label' => 'amount left',
'rules' => 'trim|required'
)
)
答
试试这个代码:
创建一个函数:
希望它会工作:
function check_bigger($amount,$amount_left)
{
if ($amount >= $amount_left)
{
$this->form_validation->set_message('check_bigger', 'The First &/or Second fields have errors.');
return false;
}
else
{
return true;
}
}
$v$this->input->post('amount_left');
$config=array(
array(
'field' => 'amount',
'label' => 'actual amount',
'rules' => 'trim|required|callback_check_bigger['.$v.']',
),
array(
'field' => 'amount_left',
'label' => 'amount left',
'rules' => 'trim|required'
)