![]() |
Where to Put Captcha Code? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Where to Put Captcha Code? (/showthread.php?tid=12001) |
Where to Put Captcha Code? - El Forum - 10-01-2008 [eluser]Glowball[/eluser] Hi all, I have a site with a form on every page, and that form needs a captcha. The code for the form is in a single view template used by all pages, so it is only in one place. I'd rather not put the captcha-building code in a view, but I'm not sure where else to put it. Some of my controllers have multiple functions, so it seems like it would be best to put the code in the constructor for each controller. But then it seems that I can't return the captcha image code from the constructor to pass it to the view. Do I need to put the code in each function? It seems so redundant. What would you do? Where to Put Captcha Code? - El Forum - 10-01-2008 [eluser]Mirage[/eluser] I would write a view helper function that generates the captcha, and then call that from the view. Where to Put Captcha Code? - El Forum - 10-01-2008 [eluser]Glowball[/eluser] [quote author="Mirage" date="1222901407"]I would write a view helper function that generates the captcha, and then call that from the view.[/quote] Thanks, that should work, good idea! Where to Put Captcha Code? - El Forum - 10-01-2008 [eluser]Glowball[/eluser] Great solution! I made a little helper at application/helpers/captcha_helper.php with this in it, including it in each file by putting it in my autoload.php file. Code: if (! function_exists('get_captcha')) Then in my view I just called it like so. Code: <?= get_captcha(); ?> Thanks so much for your quick help! Where to Put Captcha Code? - El Forum - 11-22-2008 [eluser]smickiedoo[/eluser] way cool! I created a helper for checking captcha as well. The whole process can be boiled down to one if statement in the controller and a function call in the view to show the captcha image. Couldn't be easier. my code: autoloaded helper captcha_check_helper.php Code: <?php autoloaded helper captcha_display_helper.php Code: <?php In the controller just do something like this Code: if(check_captcha()) And in the view Code: <?= display_captcha(); ?> Thanks |