繁体   English   中英

CodeIgniter:提交表格 <enter> 表单验证失败

[英]CodeIgniter: form submitted with <enter> fails form validation

我有CodeIgniter的这个问题: - 当我单击表单中的提交按钮时,表单被正确提交和验证 - 当我没有单击提交按钮时,只需点击<enter> ,表单验证总是失败任何解决方案? 这是CI表单验证中的缺陷还是我遗漏了一些东西?

那里有什么代码:

--- the form view ---

form_open("/");
...some inputs...
echo form_submit('submit', 'Přihlásit');
form_close();
...

--- the controller ---

$this->CI->load->helper('form');  
$this->CI->load->library('form_validation');

$this->CI->form_validation->set_rules('id_uziv', 'ID', 'required');   
$this->CI->form_validation->set_rules('heslo', 'Heslo', 'required');  
//... see, no rules have anyhting to do with the submit button

if ($this->CI->form_validation->run() == FALSE) {
  // validation OK
}
else {
  // validation failed
}

你没有回应form_open('/')

您的表单元素不会包含在<form>元素中,因此在您提交时,不会将任何发布数据发送到服务器,从而导致验证失败。

我通过为提交按钮添加一个空的验证规则来解决它,如下所示:

$this->CI->form_validation->set_rules('submit_button', 'Submit', '');

现在它有效。 我真的不知道是什么引起了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM