【发布时间】:2015-04-19 06:05:40
【问题描述】:
我有两个日期字段来收集用户的数据。需要使用 codeigniter 表单验证类对其进行验证。
场景:
-
第一个日期字段可以为空
-
第二个日期字段不能为空
-
第一个日期字段不应大于今天的日期
-
第二个日期字段应该大于第一个日期字段
$this->form_validation->set_rules('first_field', 'First Field', 'trim|required');
$this->form_validation->set_rules('second_field', '第二字段', 'trim|required|callback_check_equal_less['.$this->input->post('first_field').']');
而回调函数是:
function check_equal_less($second_field,$first_field)
{
if ($second_field <= $first_field)
{
$this->form_validation->set_message('check_equal_less', 'The First &/or Second fields have errors.');
return false;
}
else
{
return true;
}
}
【问题讨论】:
-
抱歉,不太清楚。你都尝试了些什么 ?你发现了什么错误?
-
我无法格式化代码。如果我按下并单击 ({}) 按钮或 (Ctrl+k),则其格式不正确。 :(
标签: php forms validation codeigniter