您好我想做一個簡單的驗證表單,但出於某種原因,它不工作我試圖休閒codeigniter用戶指南,但它不適用於我出於某種原因,我只是一個初學者。有人可以看看我的代碼,並幫助我解決問題。我所得到的是一個錯誤信息頁面未找到,並且表單本身無法驗證。當我短聲提交按鈕它去這個網址HTTP://localhost/Surva/index.php/info/validation
試圖驗證形式使用codeigniter
控制器
<?php
class Info extends CI_Controller{
public function index(){
$this->load->view('info_view');
$data ['name'] = $this->input->post('name');
$data ['second_name'] = $this->input->post('second_name');
$data ['phone'] = $this->input->post('phone');
$data ['email'] = $this->input->post('email');
if($this->input->post('submit')){
$this->form_validation->set_rules('name', 'Name', 'required|alpha|xss_clean');
$this->form_validation->set_rules('second_name', 'Second Name', 'required|alpha|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if ($this->form_validation->run()){
$this->info_model->add_record($data);
}
}
$this->load->view('survay_view');
}
}
?>
視圖
<html>
<head>
</head>
<body>
<?php
echo validation_errors();
echo form_open('info/validation'); ?>
<ul id="info">
<li><label for='name'>Name:</lable><?php echo form_input('name')?></li>
<li><label for='second_name'>Second Name:</lable> <?php echo form_input('second_name');?> </li>
<li><label fro='phpne'>Phone:</lable> <?php echo form_input('phone');?></li>
<li><label for='email'>Email:</lable><?php echo form_input('email');?></li>
<li><?php echo form_submit('submit', 'Start survay!!');?></li>
</ul>
<?php echo form_close();?>
</body>
</html>
模式
<?php
class Info_model extends CI_Model {
function get_records()
{
$query = $this->db->get('credentials');
return $query->result();
}
function add_record($data)
{
$this->db->insert('credentials', $data);
return;
}
}
?>
你加載了form_validation庫嗎? – 2013-03-04 07:30:36
其自動加載 – 2013-03-04 07:33:41
什麼不適合你?你是否收到任何錯誤或其驗證字段? – 2013-03-04 07:39:31