Kohana form Validation tutorial (Kohana3.3)

Source: Internet
Author: User
Tags kohana
The official Kohana form Validation tutorial is a bit rough. I have been reading it for half a day. This tutorial is a serialization tutorial, data or the previous data structure (KohanaORM) Step 1: In application/model/

The official Kohana form Validation tutorial is a bit rough. I have been reading it for half a day. This tutorial is a serialization tutorial, data or the data structure (Kohana ORM) described above)
Step 1: write verification rules in application/model/article. php:

// Verification rule public function rules () {return array ('CID' => array ('not _ empty ')), 'title' => array ('not _ empty'),), 'content' => array ('not _ empty '), array ('min _ length', array (': value', 4), array ('max _ length', array (': value ', 40 )),),);}

Step 2: write the verification prompt information in application/messages/models/article. php (create a directory without it)
 */Return array ('CID' => array ('not _ empty' => 'Article category cannot be blank '), 'title' => array ('not _ empty' => 'Article title cannot be blank '), 'content' => array ('not _ empty' => 'Article content cannot be blank ', 'min _ length' =>' content must be at least 4 characters ', 'max _ length' => 'content cannot exceed 40 characters '));

Step 3: compile the foreground html file: application/views/welcome/index. php
            PHP dot-http://www.phpddt.com        
                            

Step 4: compile the Controller file application/controller/welcome. php:
 find_all();            $this->template->category = $category;            if($_POST)            {                $artile = ORM::factory('article')->values($_POST);                  $vali = Validation::factory($_POST, '_external', array());                try{                        $artile->save($vali);                }                 catch (ORM_Validation_Exception $e)                 {                    $this->template->errors = $e->errors('models');                }            }        }}

If the verification rule is not met, an error is prompted, such:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.