[英]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.