表单验证CodeIgniter错误

时间:2015-10-26 04:46:23

标签: php codeigniter frameworks

有人知道CI中的表单验证吗? 只要这个脚本在我的函数中,它就会给出错误 我不知道为什么,我只是从用户指南中复制粘贴,并将其放入我的功能

而且,我不能做autoload.php - > $ autoload ['libraries'] = array('database','session');

这是表单验证的代码:

$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('item_name', 'Item Name', 'is_numeric|required');
$this->form_validation->set_rules('item_price', 'Item Price', 'required');
$this->form_validation->set_rules('item_description', 'Item Description', 'required');
if ($this->form_validation->run() == FALSE)
{
  $this->create();
}else{
    $this->load->view('formsuccess');
}

请帮帮我们..

first error of form validation

second error of form validation

完整代码:

function submit(){

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


  $this->form_validation->set_rules('item_name', 'Item Name', 'is_numeric|required');
  $this->form_validation->set_rules('item_price', 'Item Price', 'required');
  $this->form_validation->set_rules('item_description', 'Item Description', 'required');


  if ($this->form_validation->run() == FALSE)
  {
  $this->create();
   }
     else
     {
   $this->load->view('formsuccess');
     }
}

2 个答案:

答案 0 :(得分:0)

试试这个:

$this->load->model('login_database','file');

$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('item_name', 'Item Name', 'is_numeric|required');
$this->form_validation->set_rules('item_price', 'Item Price', 'required');
$this->form_validation->set_rules('item_description', 'Item Description', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('formsuccess');
}else
{
$this->create();
}

答案 1 :(得分:0)

使用HMVC时

别忘了使用MX_controller。

这是我问题的完整解决方案:

看起来你正在使用HMVC请不要显示完整的template.php文件,如果控制器文件应该是大写的第一个字母名称和文件名示例Template.php和类模板扩展MX_Controller {}

相关问题