|
本帖最后由 flourishing 于 2012-9-25 14:40 编辑
疑问:是否表单移动要form辅助函数来写,直接用html写不行吗?
目前是验证类无反应,也没有数据提交,参照教程写的。
下面是几个文件的代码,请指正
form表单
PHP复制代码
<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复制代码
<?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[passwordcheck]');
//$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复制代码
<?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);
}
}
复制代码
|
|