Here we are integrating our custom form with magento's default captcha. For example we can add captcha to contactform of Magento

Step 1

First add captcha block to contacts form and add this code to local.xml

        
            
                
                    
                        mage/captcha.js
                    
                    contacts
                    230
                    50
                
            
        
    

Step 2

Go to admin → customers → customer configuration → captcha

On enabling captcha, a forms field will appear as shown below.

Add the contacts form under the forms section as shown in the above image. Add the following code to the config.xml file

        
            
                
                    
                        
                    
                
            
        
        
            
                
                    1
                
            
        
    

Refresh the page so that you can see that contacts page is added to the forms section

Step 3

Finally call the captcha block in phtml file. Add this code to contact.phtml file

 

Thats it! we have added captcha to contacts form as shown below.

Captcha in Custom Forms

In some cases we cannot call the “ form.additional.info”  as a child block in our phtml file. In that case we can add captcha by calling the singleton to get the   capatcha block object in corresponding phtml file.

For eg: if require to add captcha in our custom form say in  a  “quote” form, follow the steps,

Step 1

Add the “quote” form under the forms section.

        
            
                
                    
                        
                    
                
            
        
        
            
                
                    1
                
            
        
    

Step 2

Call the singleton  to have the block object of captcha in the phtml file.

 

Thats it! Captcha will be displayed in “quote” form.

We can reduce the lines in captcha by overriding lib → zend → captcha → Image.php and change the protected $_dotNoiseLevel and protected $_lineNoiseLevel values.