Craft\AmForms_RecaptchaService::render PHP Method

render() public method

Render a reCAPTCHA widget.
public render ( ) : boolean | string
return boolean | string
    public function render()
    {
        // Get reCAPTCHA settings
        $recaptchaSettings = craft()->amForms_settings->getAllSettingsByType(AmFormsModel::SettingRecaptcha);
        // Is reCAPTCHA enabled?
        if ($recaptchaSettings && $recaptchaSettings['googleRecaptchaEnabled']->value) {
            // Plugin's default template path
            $templatePath = craft()->path->getPluginsPath() . 'amforms/templates/_display/templates/';
            // Build reCAPTCHA HTML
            $oldPath = method_exists(craft()->templates, 'getTemplatesPath') ? craft()->templates->getTemplatesPath() : craft()->path->getTemplatesPath();
            method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($templatePath) : craft()->path->setTemplatesPath($templatePath);
            $html = craft()->templates->render('recaptcha', array('siteKey' => $recaptchaSettings['siteKey']->value));
            // Reset templates path
            method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($oldPath) : craft()->path->setTemplatesPath($oldPath);
            // Include Google's reCAPTCHA API
            craft()->templates->includeJsFile('https://www.google.com/recaptcha/api.js');
            // Parse widget
            return new \Twig_Markup($html, craft()->templates->getTwig()->getCharset());
        }
        return false;
    }
AmForms_RecaptchaService