lwcompany

功到自然成

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

1.建立表think_form

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2012 年 09 月 06 日 02:51
-- 服务器版本: 5.5.8
-- PHP 版本: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- 数据库: `myapp`
--

-- --------------------------------------------------------

--
-- 表的结构 `think_form`
--

CREATE TABLE IF NOT EXISTS `think_form` (
  `id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `content` varchar(255) NOT NULL,
  `create_time` int(11) unsigned NOT NULL,
  `update_time` int(11) unsigned NOT NULL,
  `status` tinyint(1) unsigned NOT NULL,
  `email` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;

--
-- 转存表中的数据 `think_form`
--

INSERT INTO `think_form` (`id`, `title`, `content`, `create_time`, `update_time`, `status`, `email`) VALUES
(1, '这是测试数据', 'dfdf', 1212724876, 0, 1, 'dddd@ddd.com'),

2. http://localhost/lw/thinkphplnkq/Myapp/action/IndexAction.class.php

<?php
class IndexAction extends Action{
    public function index() {
           $this->assign('title','添加数据');//这里设置了模板变量{$title}
           $this->display();        
    }
 

public function add()  {
          $Form = D("Form");
          if($vo=$Form->create()) {
            if($Form->add()){
            $this->success('添加成功');
          }    else{
             $this->error('添加失败');
          }
         }
        }

?>

3. Myapp\Tpl\index\index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>{$title}</title>
</head>
<body>
<form action="__URL__/index/add" method="post" name="formname" id="formname">
    <p>
           <label for="title">标题</label>
           <input name="title" type="text" id="title" />
    </p>
    <p>
           <label for="email">邮箱</label>
          <input name="email" type="text" id="email" />
    </p>
    <p><label for="content">内容�</label></p>
    <p>
        <textarea name="content" rows="5" cols="25" id="content" class="textarea" ></textarea>
    </p>
    <p><input type="submit" value="提交" /></p>
</form>
</body>
</html>

注意事项:method="post" 为默认的提交方法,没有此句将出现(bool)false错识误提示

4关于表单令牌

表单令牌是当表单提示后系统自动在表单末尾添加一个代码端

input type="hidden" name="__hash__" value="2b57304ea08130e4654c5176f5eb30bf_ea7ecfe101e23697a836a7e0d764e5f7" /></form>

表单令牌主要作用是防止重复提交表单。

令牌配置在手册thinkphp 2.0

令牌验证配置

TOKEN_ON   =   true

是否开启令牌验证

TOKEN_NAME  =   '__hash__'

令牌验证的表单隐藏字段名称

TOKEN_TYPE    =    'md5'

令牌验证哈希规则

关闭表单令牌代码:

在配置文件CONFIG.CLASS.PHP

TOKEN_ON   =   false;

不显示定界符在html页面中加入{NOTOKKEN}

5

   .关于success.html和error.html文件查找在example例子库中。然后拷贝文件到Tpl\default\public\目录之中

   要想指出错误具体提示error($user->geterror())

6

      如果一个页面有多个表单可以在html页面中{__TOKEN__};

posted on 2012-09-06 14:29  平渡飞扬  阅读(562)  评论(0编辑  收藏  举报