File indexing completed on 2025-02-23 05:31:57

0001 <?php
0002 namespace Cgsmith\View\Helper;
0003 
0004 /**
0005  * Class FormRecaptcha
0006  *
0007  * @package Cgsmith
0008  * @license MIT
0009  * @author  Chris Smith
0010  */
0011 class FormRecaptcha extends \Zend_View_Helper_FormElement
0012 {
0013     /**
0014      * For google recaptcha div to render properly
0015      *
0016      * @param $name
0017      * @param null $value
0018      * @param null $attribs
0019      * @param null $options
0020      * @param string $listsep
0021      * @return string
0022      * @throws \Zend_Exception
0023      */
0024     public function formRecaptcha($name, $value = null, $attribs = null, $options = null, $listsep = '')
0025     {
0026         if (!isset($attribs['siteKey']) || !isset($attribs['secretKey'])) {
0027             throw new \Zend_Exception('Site key is not set in the view helper');
0028         }
0029 
0030         $customClasses = '';
0031         if( isset( $attribs['classes'] )) {
0032             if( is_array( $attribs['classes'] ) ) {
0033                 $customClasses = implode(' ', $attribs['classes']);
0034             } else {
0035                 $customClasses = $attribs['classes'];
0036             }
0037         }
0038 
0039         return '<div class="g-recaptcha ' . $customClasses . '" data-sitekey="' . $attribs['siteKey'] . '"></div>';
0040     }
0041 
0042 }