我对表单验证规则有疑问:这是控制器:
$this->load->library('form_validation');
$vL = array(
array(
"field" => $this->input->post('username'),
"rules" => "trim|required",
'errors' => array(
'required' => 'You must provide a %s.',
),
),
array(
"field" => $this->input->post('password'),
"rules" => "trim|required",
'errors' => array(
'required' => 'You must provide a %s.',
),
)
);
$this->form_validation->set_rules($vL);
if ($this->form_validation->run()) {
print "ok";
} else {
print "not ok"<br /><br />";
}
查看登录名:
echo form_open('', ['action' => '', 'id' => 'frmUsers', 'autocomplete' => 'off', 'class' => 'form-signin']);
echo form_input(['name' => 'username', 'class' => 'form-control', 'placeholder' => 'username', 'required' => 'required']);
echo form_input(['name' => 'password', 'class' => 'form-control', 'type' => 'password', 'required' => 'required']);
$data = array(
"type" => "submit",
"name" => "login",
"value" => "Sign in",
"class" => "btn btn-lg btn-primary btn-block",
);
echo form_submit($data);
我不知道问题出在哪里。也许是因为我没有标签,但是我不确定。谢谢!
在表单验证数组中,"field"
用于输入的名称,而不是其值,因此"field" => "username"
和"field" => "password"
等。>