Tuesday, 19 August 2014

Simple CakePHP captcha component for CakePHP 2.x

Here is the latest CakePHP Captcha component for CakePHP Version 2.x. Compatible up to CakePHP version 2.5.3.
NOTE:For best Image Captcha results this component requires GD and Freetype support enabled. Please check your phpinfo() to know whether your server supports this (See image below). Contact your hosting provider if any of these libraries is not enabled.
gd-free-type-enabled
Captcha-Component-for-CakePHP-2.x
Update – Sep 25, 2013
§  Supports Image and Simple Math captcha
§  Works without GD Truetype font support (NOT RECOMMENDED though)
§  Default and Random themes for Image Captcha
§  Checks for missing font file
Updated on – Sep 19, 2013
§  Had been reported of issues related to missing font file so i have updated the controller function to detect the existence of font file. Dies with error on missing font file. So don’t forget to upload attached font file. If you wanted to use a different font upload it to webroot folder and change settings['font'] parameter
Updated on – April 12, 2013
§  Random captcha images are possible. Set “theme”=>”random” in $settings variable of CaptchaComponent.php or in Controller when loading captcha component.
§  Can’t Read? Reload is possible now. A working piece of jQuery code is included in view fileadd.ctp. Be sure to include jquery library, such ashttps://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js to make Reloading of captcha working
How to make it working
Download attached zip file and extract. Copy all files placed in app folder to their corresponding locations.
I created “SignupsController” controller and Signup.php model for demonstration purpose. Create a function similar to the following in your controller.
function captcha() {
 $this->autoRender = false;
 $this->layout='ajax';
 if(!isset($this->Captcha)) { //if Component was not loaded through $components array()
 $this->Captcha = $this->Components->load('Captcha', array(
 'width' => 150,
 'height' => 50,
 'theme' => 'random', //possible values : default, random ; No value means 'default'
 )); //load it
 }
 $this->Captcha->create();
 }
Call the captcha action from within your form tag in the view file, as below:
echo $this->Session->flash();
echo $this->Form->create("Signups");
$this->Captcha->render($captchaSettings);
echo $this->Form->submit(__(' Submit ',true));
echo $this->Form->end();
And you are done! The captcha image should look like Cakephp Captcha COmponent
This component includes a model file i.e. Model/Signup.php file to demonstrate the use of model validation for captcha input by user. The validation works just like any other custom model validation in CakePHP.


21 comments:

  1. Really great work. Thanks for sharing this informative news with us.
    PHP training institute in chennai | PHP training courses





    ReplyDelete
  2. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    rpa training in Chennai

    rpa training in anna nagar | rpa training in marathahalli

    rpa training in btm | rpa training in kalyan nagar

    ReplyDelete
  3. Fantastic work! This is the type of information that should follow collective approximately the web. Embarrassment captivating position Google for not positioning this transmit higher! Enlarge taking place greater than and visit my web situate
    python training in Bangalore
    python training in pune
    python online training
    python training in chennai

    ReplyDelete
  4. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    java course in annanagar | java course in chennai


    java course in marathahalli | java course in btm layout

    ReplyDelete
  5. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 

    Data Science training in kalyan nagar | Data Science training in OMR
    Data Science training in chennai | Data science training in velachery
    Data science online training | Data science training in jaya nagar

    ReplyDelete
  6. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    angularjs online Training

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    ReplyDelete
  7. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    Software Testing Training in Chennai | Best Software Testing Institute
    Authorized Dotnet Training in Chennai | Dotnet Training in Chennai
    PHP Training in Chennai | Best PHP Training Institute |PHP syllabus



    Advanced Android Training in Chennai | Best Android Training in Chennai


    ReplyDelete
  8. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Top 250+AWS Interviews Questions and Answers 2018 [updated]
    Learn Amazon Web Services Tutorials 2018 | AWS Tutorial For Beginners
    Best AWS Interview questions and answers 2018 | Top 110+AWS Interview Question and Answers 2018
    AWS Training in Pune | Best Amazon Web Services Training in Pune
    AWS Online Training 2018 | Best Online AWS Certification Course 2018
    Best Amazon Web Services Training in Pune | AWS Training in Pune

    ReplyDelete
  9. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Data science Course Training in Chennai | Data Science Training in Chennai
    RPA Course Training in Chennai | RPA Training in Chennai
    AWS Course Training in Chennai | AWS Training in Chennai

    ReplyDelete
  10. Altorum Leren, a leading IT, Services Company, specializes in Software Development, Cloud Computing, UX/UI, IoT, Artificial Intelligence, Blockchain, DevOps, Front End Web Development, Back End Web Development, Web & Mobile App Development and moreshare somemore info.
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  11. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me. good luck
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  12. Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.keep sharing!!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete
  13. Awesome blog. Thanks for sharing this blog. Keep update like this...
    Android Training in Bangalore
    Android Classes in Pune

    ReplyDelete
  14. This post is so interactive and informative.keep update more information...
    Data Science course in Tambaram
    Data Science course in Chennai

    ReplyDelete