flourishing 发表于 2012-9-24 16:25:25

求助,不能post数据

本帖最后由 flourishing 于 2012-9-25 14:40 编辑

疑问:是否表单移动要form辅助函数来写,直接用html写不行吗?
目前是验证类无反应,也没有数据提交,参照教程写的。
下面是几个文件的代码,请指正
form表单

<p><?php echo validation_errors();?></p>
      
      <form class="form-horizontal"method="post" accept-charset="utf-8" action="<?php echo site_url('user/create'); ?>">
            <div class="control-group">
            <label class="control-label" for="inputEmail">账号</label>
            <div class="controls">
            <input type="text" id="email" placeholder="Email" value="<?php echo set_value('email'); ?>">
            </div>
            </div>
            <div class="control-group">
            <label class="control-label" for="inputPassword">密码</label>
            <div class="controls">
            <input type="password" id="password" placeholder="Password">
            </div>
            </div>
            <div class="control-group">
            <label class="control-label" for="inputPassword">确认密码</label>
            <div class="controls">
            <input type="password" id="passwordcheck" placeholder="PasswordCheck">
            </div>
            </div>

            <button type="submit" class="btn">创建用户</button>
            </div>
            </div>
      </form>


controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
function __construct()
{

   parent::__construct();
   $this->output->enable_profiler(TRUE);
    $this->load->model('user_model');
}

/**
* Index Page for this controller.
*
* Maps to the following URL
*   http://example.com/index.php/welcome
* - or -
*   http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function create()
{
   $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
   //$this->form_validation->set_rules('password', 'Password', 'trim|required|matches');
//$this->form_validation->set_rules('passwordcheck', 'Password Confirmation', 'trim|required');


    if ($this->form_validation->run() === FALSE)
    {
      $this->load->view('newuser_form');
    }
    else
    {
      $this->user_model->user_create();
      $this->load->view('index');
   
    }


}
}

model

<?php
class User_model extends CI_Model {
/*
`id`, `email`, `password`, `createtime`, `agreetime`, `usertype`
*/
public function user_create()
{

$this->load->helper('date');
$data = array(
    'email' => $this->input->post('email'),
    'password' => $this->input->post('password'),
    'createtime' => now(),
    'usertype'=>2,//0 admin,1 doctor,2 patients,3 not activated;
);

return $this->db->insert('users', $data);
}

}



cdm 发表于 2012-9-24 18:00:56

validation 你在控制器加载了没~~~

不用那么复杂了,不要CI的表单辅助功能,原生就可以。

flourishing 发表于 2012-9-24 20:08:46

在autoload里面加载了。

flourishing 发表于 2012-9-25 14:40:08

已经知道了。表单里面每个input 没有加name属性,只加了id属性
页: [1]
查看完整版本: 求助,不能post数据