|
表单页面
<h2>创建新的新闻内容</h2>
<!-- validation_errors() 报告表单验证错误信息-->
<?php echo validation_errors();?>
<?php echo form_open('news/create');?>
<label for="title">标题</label>
<input type="text" name="title" /> <br/>
<label for="content">内容</label>
<textarea name="content"></textarea> <br/>
<input type="submit" name="submit" value="创建一个新的新闻"/>
</form>
-----------
规则设置
//设置表单验证规则
// 输入域名称,错误信息名称,错误信息规则
$this->form_validation->set_rules('title','Title','required');
$this->form_validation->set_rules('content','Content','required');
//判断表单验证结果
if ( $this->form_validation->run() === false){
//表单验证失败
//$this->loadView('news/create',$data);
//echo validation_errors();
$this->load->view('news/create');
}else {
//表单验证成功
//添加数据
$this->news_model->setNews();
$this->load->view('news/success');
} |
|