view内容:

<?php echo form_open('user/reg'); ?>
<h5>用户名</h5>
<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" />
<span id="error_msg"><?php echo $this->validation->username_error; ?></span> <h5>密码</h5>
<input type="password" name="password" size="50" />
<span id="error_msg"><?php echo $this->validation->password_error; ?></span> <h5>确认密码</h5>
<input type="password" name="passconf" size="50" />
<span id="error_msg"><?php echo $this->validation->passconf_error; ?></span> <h5>Email</h5>
<input type="text" name="email" value="<?php echo $this->validation->email;?>" size="50" />
<span id="error_msg"><?php echo $this->validation->email_error; ?></span>
<div><input type="submit" value="Submit" /></div> </form>

controller内容:

$this->load->library('validation');
$this->load->helper('form'); $rules['username'] = "trim|required|min_length[5]|max_length[16]|xss_clean|callback_username_check";
$rules['password'] = "trim|required|matches[passconf]|md5";
$rules['passconf'] = "trim|required";
$rules['email'] = "trim|required|valid_email|callback_email_check";
$this->validation->set_rules($rules); $fields['username'] = '用户名';
$fields['password'] = '密码';
$fields['passconf'] = '密码确认';
$fields['email'] = '邮箱地址';
$this->validation->set_fields($fields); if ($this->validation->run() == FALSE)
{
$this->load->view('user/reg_view');
}
else
{
//调用这个函数保存数据到数据库
$this->user_model->reg();
$this->load->view('user/reg_suc_view');
}

model内容:

$activation_key = md5(uniqid() + time());
$data = array
(
'username' => $this->input->post('username'),
'password' => $this->input->post('password'),
'email' => $this->input->post('email'),
'registered_date' => time(),
'activation_key' => $activation_key,
'status'=>0,
'level'=>0,
'reserve_times'=>0,
'credit'=>0,
); $this->db->insert($this->config->item('db_prefix').'user', $data);

碰到类似的表单提交的功能,直接ctrl+c、ctrl+v,改改就能用。

CodeIgniter典型的表单提交验证代码的更多相关文章

  1. amazeUI表单提交验证--input框required

    效果: html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  2. 原生JS 表单提交验证器

    转载:http://www.cnblogs.com/sicd/p/4613628.html 一.前言 最近在开发一个新项目,需要做登陆等一系列的表单提交页面.在经过“缜密”的讨论后,我们决定 不用外部 ...

  3. aspx中的表单验证 jquery.validate.js 的使用 以及 jquery.validate相关扩展验证(Jquery表单提交验证插件)

    这一期我们先讲在aspx中使用 jquery.validate插件进行表单的验证, 关于MVC中使用 validate我们在下一期中再讲     上面是效果,下面来说使用步骤 jQuery.Valid ...

  4. Angualr6表单提交验证并跳转

    在Angular6中,使用NG-ZRROR作为前端开发框架,在进行表单开发时遇到了一些问题,最后解决了,在此记录. 1.表单构造: 引入forms: import { FormGroup, FormB ...

  5. destoon 信息发布表单提交验证

    sell 模块的form表单如下: <form method="post" id="dform" action="?" target= ...

  6. easyui表单提交验证form

    方式一,不需要考虑jquery.easyui.min.js版本 <script> $(function () { //针对 设置 novalidate:true $('.validateb ...

  7. js 日期格式、内容合法、比较大小、表单提交验证

    1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"/> 5 &l ...

  8. PHP表单提交验证各种方式

    <!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  9. ng 表单提交验证

    http://www.runoob.com/try/try.php?filename=try_ng_validate

随机推荐

  1. R语言缺失值高级处理方法

    0 引言 对于一些数据集,不可避免的出现缺失值.对缺失值的处理非常重要,它是我们能否继续进行数据分析的关键,也是能否继续大数据分析的数据基础. 1 缺失值分类 在对缺失数据进行处理前,了解数据缺失的机 ...

  2. Kubernetes Pod 健康检查

    参考文档: https://jimmysong.io/kubernetes-handbook/guide/configure-liveness-readiness-probes.html 一.Pod的 ...

  3. css基础--常用css属性02

    上篇地址:css基础--常用css属性01 本文参考菜鸟教程和w3school 1  浮动和清除浮动 在上篇的第十一节--定位中说道: CSS 有三种基本的定位机制:普通流.浮动和绝对定位. 普通流和 ...

  4. C# list.ForEach用法

    list.ForEach(delegate(T model) { ... });

  5. UIKit类图

  6. 应用jfinal发送微信模板消息的一个bug

    严格来讲,这不是一个bug,只是我们应用的方式不对.微信发送模板消息的方法是: HttpUtils.post(sendApiUrl + AccessTokenApi.getAccessTokenStr ...

  7. 手把手教你使用webpack搭建vue框架

    我们在使用vue开发项目的时候,都是用vue-cli直接来搭建的.但是这是别人已经造好的轮子,我们既然要使用别人造好的轮子,我们总不能知其然而不知其所以然.所以呢,我这边文章就教你如何使用webpac ...

  8. python学习笔记2--list

    一.list操作 list=['xiaohei','xiaobai','xiaohong']#定义一个数组 name=[]#定义一个空数组 #查 #下标是从0开始 print(list[1]) #-1 ...

  9. Windows系统环境下Solr之Java实战(一)搭建solr服务器并配置IK分词

    搭建solr服务器 1.下载地址:http://archive.apache.org/dist/lucene/solr/ 2.将D:\JavaWeb\Solr\solr-6.2.0\server\so ...

  10. bzoj1485 有趣的数列

    传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1485 [题解] Catalan数,注意不能直接用逆元,需要分解质因数. # include ...