简体   繁体   English

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

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

I have this problem with CodeIgniter: - when I click the submit button in a form, the form is submitted and validated correctly - when I don't click the submit button, just hit <enter> , the form validation always fails Any solution? 我有CodeIgniter的这个问题: - 当我单击表单中的提交按钮时,表单被正确提交和验证 - 当我没有单击提交按钮时,只需点击<enter> ,表单验证总是失败任何解决方案? Is that a flaw in CI's form validation or am I missing something? 这是CI表单验证中的缺陷还是我遗漏了一些东西?

What code I have there: 那里有什么代码:

--- 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
}

you're not echoing form_open('/') 你没有回应form_open('/')

your form elements will not be enclosed within a <form> element so when you submit, no post data will be sent to the server resulting in your validation failing. 您的表单元素不会包含在<form>元素中,因此在您提交时,不会将任何发布数据发送到服务器,从而导致验证失败。

I solved it by adding an empty validation rule for the submit button, like this: 我通过为提交按钮添加一个空的验证规则来解决它,如下所示:

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

Now it works. 现在它有效。 I don't really know what was causing the problem. 我真的不知道是什么引起了问题。

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

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