Yii implementation creates a verification code instance parsing _php instance

Source: Internet
Author: User
Tags yii
In this paper, we describe the method of Yii to create a verification code in the form of an example, as follows:

First, add the following code under Sitecontroller action ():

return Array (//CAPTCHA action renders the CAPTCHA image displayed on the contact page ' captcha ' =>array (' class ' = = ') Ccaptchaaction ', ' BackColor ' =>0xffffff,),//page action renders "static" pages stored under ' Protected/views/site/pa Ges '//They can be accessed via:index.php?r=site/page&view=filename ' page ' =>array (' class ' = ' cviewaction ',) ,);

Second, (1) Add the code under LoginForm Model Rules ():

Captche class Neededarray (' Verifycode ', ' captcha ', ' AllowEmpty ' =>! Ccaptcha::checkrequirements ()),

(2) Add properties under LoginForm Model:

Public $verifyCode;

Third, add the code under Contactform Model Rules ():

Verifycode needs to be entered Correctlyarray (' Verifycode ', ' captcha ', ' AllowEmpty ' =>! Ccaptcha::checkrequirements ()),

Iv. Add the code under Login view:

<?phpecho $form->labelex ($model, ' verifycode ');? ><?php$this->widget (' Ccaptcha ');? ><?phpecho $form->textfield ($model, ' verifycode ');? ><?phpecho $form->error ($model, ' verifycode ');? >

This example code is only the main function of the brief, the reader can also be based on their own project requirements to further refine the program code, so that its function more practical.

  • 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.