本文以实例讲述了ThinkPHP表单自动提交验证的实现过程,详细步骤如下所示:
一、模板部分:
ThinkPHP示例:表单提交、自动验证和自动填充
二、模型部分form类程序代码:
三、控制器部分indexaction类程序代码:
top6('','*','id desc');//从数据库中读取最新6条记录,并且安id倒序输出
$this->assign('list',$list);//把数据传到模板里
$this->display();
}
// 处理表单数据
public function insert() {//此方法对应表单的ACTION="__URL__/insert"
$Form = D("Form");
if($Form->create()) {//创建 Form 数据对象,默认通过表单提交的数据进行创建,为下面写入数据库做准备
$Form->add();// 新增表单提交的数据 ,吧上面创建的数据对象提交
$this->redirect();//返回上一个模块,页面跳转可以说是
}else{
header("Content-Type:text/html; charset=utf-8");
exit($Form->getError().' [ 返 回 ]');
}
}
// 生成验证码
//这个方法没什么好说的,固定格式
public function verify() {
import("ORG.Util.Image");
Image::buildImageVerify(); //这里两个冒号是调用静态方法
}
}
?>


