|
楼主 |
发表于 2016-6-17 10:04:55
|
显示全部楼层
视图
<form action="http://localhost/index.php?/blog/" method="post" accept-charset="utf-8">
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
控制器
class Blog extends CI_Controller {
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules(
'username', 'Username',
'required|min_length[5]|max_length[12]|xss_clean',
array(
'required' => 'You have not provided %s.',
'is_unique' => 'This %s already exists.'
)
);
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|matches[password]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('Blog');
}
else
{
$this->load->view('formsuccess');
}
}
} |
|