Home>

Yii is a component-based high-performance PHP framework for developing large-scale web applications. Yii is written in strict oop, and has perfect library references and comprehensive tutorials.This article introduces you to the form validation rules for the PHP yii framework.Interested friends study together

Yii is a component-based high-performance PHP framework for developing large-scale web applications. Yii is written in strict oop, and has complete library references and comprehensive tutorials.

stop talking nonsense,Post the code directly to everyone.

<?php
class contactform extends cformmodel
{
  public $_id;
  public $contact;//contact
  public $tel;//phone
  public $fax;//fax
  public $zipcode;//zip code
  public $addr;//address
  public $mobile;//mobile
  public $email;//email
  public $website;//URL
  public $qq;//qq
  public $msn;//msn
  public function rules ()
  {
    return array (
      array ("contact", "required", "on" =>"edit", "message" =>"The contact must be filled in.
"),      array ("contact", "length", "on" =>"edit", "min" =>2, "max" =>10, "tooshort" =>"Please control the contact length at 2 -10 characters. "," Toolong "=>" Please control the contact length to 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", "pattern" =>"/^ (\ d {3}-| \ d {4}-) (\ d {8} | \ d {7})? ;$/"," message "=>" Please enter the correct fax number.
"),      array ("mobile", "match", "pattern" =>"/^ 13 [0-9] {1} [0-9] {8} $| 15 [0189] {1} [0-9] {8} $| 189 [0-9] {8} $/"," message "=>" Please enter the correct mobile phone number.
"),      array ("email", "email", "on" =>"edit", "message" =>"" The mailbox has been entered incorrectly.
"),      array ("zipcode", "required", "on" =>"edit", "message" =>"
"),      array ("zipcode", "numerical", "on" =>"edit", "message" =>"" zip code is 6 digits. "),      array ("zipcode", "length", "on" =>"edit", "min" =>6, "max" =>6, "tooshort" =>>"," toolong "=>" Zip code is 6 digits long. "),      array ("website", "url", "on" =>"edit", "message" =>"" The URL is entered incorrectly.
"),      array ("qq", "match", "pattern" =>"/^ [1-9] {1} [0-9] {4,11} $/", "message" =>"Please enter Correct qq number. "),      array ("msn", "email", "on" =>"edit", "message" =>"msn was entered incorrectly.
"),    );
  }
}

Full example:

public $password2;//Non-database fields,But need to use in view
  public $verify;//mobile 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";
  }
  /**
   * Verification rules
   * @return array validation rules for model attributes.
   * /
  public function rules ()
  {
    //note:you should only define rules for those attributes that
    //will 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 information Operator's mobile number.
"),      //array ("certificate_id", "match", "pattern" =>"/(.jpg|.gif|.png|\d)$/","message" =>"Please reselect the certificate image and The 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 password and confirm password
      array ("password2", "compare", "compareattribute" =>"password", "message" =>"Passwords do not match twice", "on" =>"register"),      array ("password2", "compare", "compareattribute" =>"password", "message" =>"Passwords do not match twice", "on" =>"regonter"),      array ("qq", "match", "pattern" =>"/^ [1-9] {1} [0-9] {4,11} $/", "message" =>"Please enter 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" =>"Invalid verification code", "integeronly" =>true),      array ("name, user_type, tuijianren", "length", "max" =>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", "default", "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 * 1024 * 10, //10mb
//"toolarge" =>"File size cannot exceed 10m!",//"message" =>"Please upload the certificate image first.
"
//),      //the following rule is used by search ().
      //@todo please remove those attributes that should not be 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 "),    );
  }
  /*
   * Phone verification code verification
   * /
  public function checkverify ($attribute, $params)
  {
    $model=new mess ();
    $d_title=$model->find (array ("condition" =>"suij =:suij and tel =:tel and type>:type and time>:time", "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 verification code is incorrect.
");
    }
    else
    {
      if ($this->password == $this->password2)
      {
        $model->updateall (array ("type" =>0), array ("condition" =>"suij =:sj", "params" =>array (":sj" =>$this ->Verify)));
      }
    }
  }

The above code is all about the form validation rules for the php yii framework.Hope you like it.

php
  • Previous Analysis of jQuery chain operation examples
  • Next Application examples of Python parsing XML through DOM and SAX