PHP yii framework of form validation rules Daquan, YII framework _php Tutorial

Source: Internet
Author: User
Tags php framework

PHP yii framework of form validation rules Daquan, YII framework


Yii is a high-performance, component-based PHP framework for developing large Web applications. Yii is written in strict OOP, with well-established library references and comprehensive tutorials.

Not much nonsense to say, directly to everyone put the code.

<?phpclass Contactform extends cformmodel{public $_id; public $contact;//Contact public $tel;//Telephone public $fax;//Fax public $zipcode;//Postal code public $ADDR;//Address public $mobile;//Mobile P      Ublic $email;//mailbox public $website;//URL public $qq,//QQ public $msn,//MSN Public Function rules () {return Array ( Array (' contacts ', ' required ', ' on ' + '-' edit ', ' message ' = ' contact ' must be filled in. '), Array (' contacted ', ' length ', ' on ' = ' edit ', ' min ' =>2, ' Max ' =>10, ' tooshort ' + ' contact length please control at 2-10 characters. ', ' toolong ' = ' + ' contact length please control in 2-10 characters. '), Array (' Tel ', ' Match ', ' pattern ' = '/^ ' (\d{3}-|\d{4}-) (\d{8}|\d{7})? $/', ' message ' = = ' Please enter the correct phone number. '), array (' Fax ', ' Match ', ' Pat ' Tern ' + '/^ (\d{3}-|\d{4}-) (\d{8}|\d{7})? $/', ' message ' = = ' Please enter the correct fax number. '), Array (' Mobile ', ' match ', ' pattern ' =&G T '/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/', ' message ' = ' Please enter the correct mobile number. '), array (' email ', ' email ', ' On ' + ' edit ', ' message ' = ' email ' is incorrectly entered. '), Array (' zipcode ', ' required ', ' on ' = ' edit ', ' MessaThe ge ' = = ' zip code must be filled in. '), Array (' ZipCode ', ' numerical ', ' on ' = ' edit ', ' message ' = ' zip ') is 6 digits. '), Array (' ZipCode ', ' Leng Th ', ' on ' + ' edit ', ' min ' =>6, ' Max ' =>6, ' tooshort ' and ' p ' are 6 digits in length. ', ' toolong ' = ' + ' ZIP code is 6 digits long. '), Array (' Website ', ' url ', ' on ' + ' edit ', ' message ' + ' URL entered incorrectly. '), Array (' QQ ', ' match ', ' pattern ' = '/^[1-9]{1}[0-9]{4,11  }$/', ' message ' + ' Please enter the correct QQ number. '), array (' MSN ', ' email ', ' on ' = ' edit ', ' message ' = ' MSN input ' is incorrect. '); }}

Complete Example:

Public $password 2;//fields for non-databases, but public $verify are required in view; Phone verification Code Public $FJG; Forgot number/** * Map database table name * @return string The associated database table name

* Www.shouce.ren */Public Function TableName () {return ' adm_user '; }/** * Validation rules * @return Array validation rules for model attributes. */Public Function rules () {//note:you should-define rules for those attributes that//would receive user Inputs. Return Array (//array (' mobile_phone,name,status ', ' required '), Array (' Mobile_phone ', ' unique '),//' message ' = = ' The phone number already exists! ' Array (' Mobile_phone ', ' match ', ' pattern ' = '/^ ' (13|15|18) [0-9]{9}$/', ' message ' = ' = ' Please enter the correct operator's mobile number. '),//array (' C ertificate_id ', ' match ', ' pattern ' = '/(. Jpg|. Gif|. png|\d) $/', ' message ' = ' Please re-select the certificate image and suffix can only be jpg, GIF, PNG format. '), array (' phone ', ' match ', ' pattern ' = '/^ ') (\d{3}-|\d{4 }-)? (\d{8}|\d{7})? $/', ' message ' = = ' Please enter the correct landline number. '), array (' Fax ', ' match ', ' pattern ' = '/^ ' (\d{3}-|\d{4}-) (\d{8}|\d{7 })? $/', ' message ' = ' Please enter the correct fax number. ',//array (' email_address ', ' match ', ' pattern ' = '/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$/', ' message ' => ' Please enter the correct email. '), Array (' email_address ', ' email ', ' message ' = ' = ' Please enter the correct email address. '),//Verify the password and Confirm password Array ("Password2", "comp Is "," Compareattribute "and" Password "," message "=" two times password Inconsistent ", ' on ' = ' register '), Array (" Password2 "," compare "," compareattribute "=" password "," message "=" two times password Inconsistent ", ' on ' = ' regonter '), Array (' QQ ', ' match ', ' pattern ' = > '/^[1-9]{1}[0-9]{4,11}$/', ' message ' = ' Please enter the correct QQ number. '), Array (' Type,certificate_id,company_type, nationality , yyzz_id, status,level,create_by_id, Create_time,update_time ', ' numerical ', ' integeronly ' =>true), Array (' Verify ' , ' numerical ', ' message ' = ' Verification Code incorrect ', ' integeronly ' =>true ', Array (' Name,user_type,tuijianren ', ' length ', ' Max ' =& GT;20), Array (' password ', ' length ', ' Max ' =>100), array (' email_address,business ', ' length ', ' Max ' =>50), Array (' Communication_address,money, Yhzh,yhmc,industry, company, Register_address,yhdh,shangbiao,zhuanli, Gongshang ', ' length ', ' Max ' =>255), array (' Role_id ', ' Default ', ' Setonempty ' =>true, ' value ' =>10), array (' Shangbiao ', ' Default ', ' Setonempty ' =>true, ' Value ' = ' = ' 0,0 '), Array (' Zhuanli ', ' Default ', ' Setonempty ' =>true, ' value ' = ' 0,0 '), Array (' Gongshang ', ' DEFA Ult ', ' setonempty ' =>true, ' value ' = ' 0,0 '), Array (' Password ', ' Default ', ' Setonempty ' =>true, ' value ' = ') 123456 '),/* Verification code */Array (' Verify ', ' checkverify ', ' on ' = ' register '), Array (' email_address ', ' checkemail ', ' On ' = ' + ' regonter '),//Array (' certificate_id ', ' file ', ' AllowEmpty ' =>true,//' types ' = ' jpg ', GIF, PNG, doc , txt ',//' maxSize ' =>1024 * 1024x768 *,//10mb//' toolarge ' = ' file size cannot exceed 10m! ',//' message ' =&gt ;' Please upload the certificate image first. ' ),//The following rule is used by search (). @todo Please remove those attributes, should not being searched. Array (' Id,role_id,name, Password,user_type, Email_address,tuijianren,shangbiao,company_type,zhuanli,gongshang, Money,yhzh,yhmc,yyZz_id,yhdh,type,level, phone, QQ, mobile_phone, fax, communication_address, nationality, industry, company, Business, Register_address, certificate, status, create_by_id, Create_time, Update_time ', ' safe ', ' on ' = ' search '); }/* * Mobile Verification Code Check */Public function checkverify ($attribute, $params) {$model =new Mess (); $d _title = $model->find (Array (' condition ' = ' suij=:suij and Tel=:tel and Type>:type ', ' Params ' =>array (': suij ' = $this->verify, ': tel ' = = $this->mobile_phone, ': Type ' =>0, ': time ' = = ( Time () -3600)), ' Select ' =>array (' id ')); $d _title = $model->findbyattributes (Array (' suij ' = $this->verify, ' tel ' = = $this->mobile_phone), Array (' SELECT ' =>array (' id '))); if ($d _title[' id ']<1) {$this->adderror (' Verify ', "The captcha is incorrect. "); } else {if ($this->password = = $this->password2) {$model->updateall (Array (' type ' =>0), a Rray (' condition ' = ' suij=:sj ', ' params ' =>array (': SJ ' = $this->verify)]); } } }

The above code is about the PHP yii framework of the form validation rules Daquan all the content, I hope you like.

http://www.bkjia.com/PHPjc/1072189.html www.bkjia.com true http://www.bkjia.com/PHPjc/1072189.html techarticle PHP yii Framework Form validation rules Daquan, YII framework Yii is a component-based high-performance PHP framework for the development of large-scale Web applications. Yii is written in strict OOP and has a perfect library ...

  • Related Article

    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.