如何在单个消息 Codeigniter 中显示验证错误?
How to show validation errors in the single message Codeigniter?
我在使用 codeigniter 时遇到问题,在检查字段时显示如下错误:
The Username field is required. The Password field is required.
The Another field is required
但我需要这样的:
Required fields a Username, Password, Another.
怎么做?
我不会那样做。但是你有很多选择。例如:根本不要使用表单验证库或开发自己的。尝试这样的事情:
$errorArray = array();
if (!$this->input->post('username')) {
$errorArray[] = 'Username';
}
if (!$this->input->post('Password')) {
$errorArray[] = 'Password';
}
if (count($errorArray)!==0) {
$allErrorFields = implode(",", $errorArray);
$errorMessage = 'Required fields: '.$allErrorFields;
$data['errorMessage'] = $errorMessage;
}
$this->load->view('myview', $data);
我在使用 codeigniter 时遇到问题,在检查字段时显示如下错误:
The Username field is required. The Password field is required.
The Another field is required
但我需要这样的:
Required fields a Username, Password, Another.
怎么做?
我不会那样做。但是你有很多选择。例如:根本不要使用表单验证库或开发自己的。尝试这样的事情:
$errorArray = array();
if (!$this->input->post('username')) {
$errorArray[] = 'Username';
}
if (!$this->input->post('Password')) {
$errorArray[] = 'Password';
}
if (count($errorArray)!==0) {
$allErrorFields = implode(",", $errorArray);
$errorMessage = 'Required fields: '.$allErrorFields;
$data['errorMessage'] = $errorMessage;
}
$this->load->view('myview', $data);