用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2126|回复: 2
收起左侧

[HELP] form_submit提交无法接收的问题

[复制链接]
发表于 2013-8-18 11:11:00 | 显示全部楼层 |阅读模式
各位高手朋友,请指点,先谢谢~~

control 文件
PHP复制代码
[/code]
<?php
class Message extends CI_Controller{
   function __construct(){
     parent::__construct();
         header('content-type:text/html charset=utf-8');
         $this->load->helper(array('form','url'));
         $this->load->model('Message_model');
         $this->load->database();
         $this->load->library('table');
 
   }
 
   function index(){
      $this->load->view('message_view');
 
   }
 
   function post(){
 
     $data=array(
                 'name'=>$this->input->post('name'),
                 'email'=>$this->input->post('email'),
                 'title'=>$this->input->post('title'),
                 'content'=>$this->input->post('content'),
                 'date'=>date('Y-m-d',time())
                 );
         
 
         $this->Message_model->insert('message',$data);
         redirect(site_url());
   }
    function test(){
                $shiyishi=$this->input->post('shiyishi');
          $this->load->view('test_view',$shiyishi);
       
        }
}
?>
 
model文件,链接数据库
[code=PHP]
复制代码

<?php
class Message_model extends CI_Model{
     function __construct(){
                 parent::__construct();
         }

         function show($table='message'){
           $query=$this->db->get($table);
           return $query;
         }

     function insert($table='message',$data){
           $this->db->insert($table,$data);
         }

         function show_where($table='message',$id){
         $this->db->where('id',$id);
         }
}
?>

view文件,view文件
[code=HTML][/code]
<html>
<head>
<title>我也会做留言本</title>
</head>
<h1>欢迎您给我留言,我将第一时间回复</h1>
<body>
<?php

$query=$this->Message_model->show('message');
if($query->num_rows()>0){
  echo $this->table->set_heading('姓名','主题','内容','时间','留言处理');
     foreach($query->result() as $row){
         $delete=anchor(site_url('message/edit'.$row->id),'删除');
         $reply=anchor(site_url('message/reply'.$row->id),'回复');
         $row->action=array($delete,$reply);

                 $this->table->add_row($row->name,$row->title,$row->content,$row->name,$row->date,$row->action);
  }
        echo $this->table->generate();
     }

  echo "<hr/>";
  echo form_open('message/post');
  echo '<br/>姓名:'.form_input('name');
  echo '<br/>邮箱:'.form_input('email');
  echo '<br/>标题:'.form_input('title');
  echo '<br/>内容:'.form_textarea('content');
  echo form_submit('submit','提交');

  echo form_close();

   ?>
  </body>
  </html>


但是view 中form_submit提交的时候要不没有反应,要不就是“网页无法访问”,我个人觉得是重定向的问题,但是又不知道如何调试,所以还请知道的朋友指导一下,谢谢了!!




发表于 2013-8-19 22:40:54 | 显示全部楼层
采用表单验证函数,要使用form的helper,建议看下示例写法,视频教程里有。

我只能说现在写的啥都不是==
发表于 2013-8-20 05:42:41 | 显示全部楼层
你根据你的情况用这段语句分别验证你的数据数组值是否传递正确:
1. 在控制器input了所有表单数据之后
print_r($data);die;
检查数据是否传递到了控制器。
2.控制器传递成功那在模型部分里insert的方法里第一行写
print_r($data);die;
检查是否传递到了模型

本版积分规则