Add Captcha to custom forms

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
modemmike
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Thu Mar 25, 2010 1:44 am

Add Captcha to custom forms

Post by modemmike » Sun Feb 03, 2013 7:29 pm

I've read a bunch of posts but none of them seem to work, whats the easiest way to add captcha to a custom form? I have recaptcha installed and working but I have a component that made custom for me and the developer seems to have disappeared. I just want to enabled the global captcha on the form.
<form method="post" action="<?php echo JRoute::_('index.php?option=com_vacation&task=form.save') ?>" onsubmit="return checkform(this);" name="My-Vacation-Form" id="My-Vacation-Form" class="form-validate">
<input type="submit" value="Submit - Go get me the best deal!" name="submit"/>
<?php echo JHTML::_( 'form.token' ); ?>
I thought I could just drop in {captcha} but no such luck.

Thanks for reading!

User avatar
Ratmil
Joomla! Explorer
Joomla! Explorer
Posts: 318
Joined: Sat Dec 06, 2008 7:07 pm

Re: Add Captcha to custom forms

Post by Ratmil » Tue Feb 05, 2013 9:44 pm

I hope this helps. You will have to write some code anyway:

Code: Select all

<?php 
  JPluginHelper::importPlugin('captcha');
   $dispatcher = JDispatcher::getInstance();
   $dispatcher->trigger('onInit','dynamic_recaptcha_1');
?>
 <p><span>Enter the code shown in the box below: <font style="color:#F00;">*</font></span></p>
            <p><div id="dynamic_recaptcha_1"></div></p><br />

Code: Select all

//Validating captcha
   $code= JRequest::get('recaptcha_response_field');     
   JPluginHelper::importPlugin('captcha');
   $dispatcher = JDispatcher::getInstance();
   $res = $dispatcher->trigger('onCheckAnswer',$code);
   if(!$res[0]){
    die('Invalid Captcha');
   }

modemmike
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Thu Mar 25, 2010 1:44 am

Re: Add Captcha to custom forms

Post by modemmike » Tue Feb 05, 2013 10:12 pm

Thanks for trying Ratmil but I can't even get the first bit of code to work. Captcha doesn't even get displayed which is my first obstacle. I don't even have a clue where to put the second bit of code.


Locked

Return to “Joomla! 2.5 Coding”