开发者

CodeIgniter: form submitted with <enter> fails form validation

开发者 https://www.devze.com 2023-01-27 23:23 出处:网络
I have this problem with CodeIgniter: - when I click the submit button in a form, the form is submitted and validated correctly

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? Is that a flaw in CI's form validation or am I missing something?

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('/')

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号