| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\FormBuilder\Components; |
| 4 |
|
| 5 |
class Recaptcha extends BaseComponent |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Compile and echo the html element |
| 9 |
* @param array $data [element data] |
| 10 |
* @param stdClass $form [Form Object] |
| 11 |
* @return viod |
| 12 |
*/ |
| 13 |
public function compile($data, $form) |
| 14 |
{ |
| 15 |
$elementName = $data['element']; |
| 16 |
$data = apply_filters('fluenform_rendering_field_data_'.$elementName, $data, $form); |
| 17 |
|
| 18 |
wp_enqueue_script( |
| 19 |
'google-recaptcha', |
| 20 |
'https://www.google.com/recaptcha/api.js', |
| 21 |
array(), |
| 22 |
FLUENTFORM_VERSION, |
| 23 |
true |
| 24 |
); |
| 25 |
|
| 26 |
$key = get_option('_fluentform_reCaptcha_details'); |
| 27 |
if($key && isset($key['siteKey'])) { |
| 28 |
$siteKey = $key['siteKey']; |
| 29 |
} else { |
| 30 |
$siteKey = ''; |
| 31 |
} |
| 32 |
|
| 33 |
$recaptchaBlock = "<div |
| 34 |
data-sitekey='{$siteKey}' |
| 35 |
id='fluentform-recaptcha-{$form->id}' |
| 36 |
class='ff-el-recaptcha g-recaptcha' |
| 37 |
data-callback='fluentFormrecaptchaSuccessCallback'></div>"; |
| 38 |
|
| 39 |
$label = ''; |
| 40 |
if (!empty($data['settings']['label'])) { |
| 41 |
$label = "<div class='ff-el-input--label'><label>{$data['settings']['label']}</label></div>"; |
| 42 |
} |
| 43 |
|
| 44 |
$el = "<div class='ff-el-input--content'><div data-fluent_id='".$form->id."' name='g-recaptcha-response'>{$recaptchaBlock}</div></div>"; |
| 45 |
$atts = $this->buildAttributes( |
| 46 |
\FluentForm\Framework\Helpers\ArrayHelper::except($data['attributes'], 'name') |
| 47 |
); |
| 48 |
$html = "<div class='ff-el-group' {$atts}>{$label}{$el}</div>"; |
| 49 |
echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form); |
| 50 |
} |
| 51 |
} |
| 52 |
|