我有一个在 codeigniter 中开发的网站。我想验证表单并显示一些消息。使用我的代码,如果我的输入“name_it”为空,我看不到任何错误。为什么?这是我的控制器:
public function nation_create()
{
if($_POST)
{
//salvo i dati
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<p class="error">Errore: ', '</p>');
$this->form_validation->set_rules('name_it', 'name_it', 'required');
if ($this->form_validation->run() !== FALSE){
$this->Nation_model->createNation();
redirect('backend/nation/nation_list/');
}
else{
$data['errors'] = validation_errors();
$this->load->view('backend/include/header_view_logged');
$this->load->view('backend/nation_create_view',$data);
$this->load->view('backend/include/footer_view');
}
}
else{
$this->load->view('backend/include/header_view_logged');
$this->load->view('backend/nation_create_view');
$this->load->view('backend/include/footer_view');
}
}
这是我的观点(我已经删减了更多代码以便阅读)
<form action='' method='POST'>
<?php echo validation_errors();
if (isset($errors))
echo $errors;
?>
<?php echo form_error('name_it'); ?>
<input type="text" name="name_it" />
<span id="errorsDiv_name_it"></span>
</form>