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<br><br> * 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. '),//Verify the password and confirm the password Array ("Password2", "compare", "compareattribute" = "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,certificat E_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 (' NA Me,user_type,tuijianren ', ' length ', ' Max ' =>20), array (' password ', ' length ', ' Max ' =>100), array (' EMAIL_ADDR Ess,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 ' =& Gt;true, ' value ' = ' 0,0 '), Array (' Gongshang ', ' Default ', ' Setonempty ' =>true, ' value ' = ' 0,0 '), Array (' Pass Word ', ' default ', ' Setonempty ' =>true, ' value ' = ' 123456 '),/* Verification code */Array (' Verify ', ' checkverify ', ' on ' = ' R ') Egister '), 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 ' = ' Please upload the certificate image first. ' ),//The following rule is used by search (). @todo Remove thOSE attributes that 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 (' type ' = 0), Array (' 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.