嗨,我正在尝试制作一个简单的验证表单,但由于某种原因它无法正常工作帮帮我 tnx 为你提供帮助。我得到的只是找不到错误消息页面,并且表单本身没有验证。当我单击提交按钮时,它会转到此 urlHTTP://localhost/Surva/index.php/info/validation
控制器
<?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;
}
}
?>