1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace fieldwork\components; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Displays a Google ReCaptcha field |
7
|
|
|
* @package fieldwork\components |
8
|
|
|
*/ |
9
|
|
|
class Recaptcha extends Field |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
private $siteKey; |
13
|
|
|
private $secretKey; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Creates a new recaptcha field with the provided keys |
17
|
|
|
* @param string $label |
18
|
|
|
* @param string $siteKey |
19
|
|
|
* @param string $secretKey |
20
|
|
|
*/ |
21
|
|
|
function __construct ($label, $siteKey, $secretKey) |
22
|
|
|
{ |
23
|
|
|
parent::__construct('recaptcha', $label); |
24
|
|
|
$this->siteKey = $siteKey; |
25
|
|
|
$this->secretKey = $secretKey; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getAttributes () |
29
|
|
|
{ |
30
|
|
|
$attributes = array_merge(parent::getAttributes(), array( |
31
|
|
|
'data-sitekey' => $this->siteKey |
32
|
|
|
)); |
33
|
|
|
unset($attributes['value']); |
34
|
|
|
unset($attributes['name']); |
35
|
|
|
return $attributes; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getClasses () |
39
|
|
|
{ |
40
|
|
|
return array_merge(parent::getClasses(), array( |
41
|
|
|
'g-recaptcha' |
42
|
|
|
)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getSiteKey () |
49
|
|
|
{ |
50
|
|
|
return $this->siteKey; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getSecretKey () |
57
|
|
|
{ |
58
|
|
|
return $this->secretKey; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Gets the HTML markup of the component |
63
|
|
|
* |
64
|
|
|
* @param bool $showLabel |
65
|
|
|
* |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
public function getHTML ($showLabel = true) |
69
|
|
|
{ |
70
|
|
|
return sprintf('<div %s></div>', $this->getAttributesString()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getName ($asMarkup = false) |
74
|
|
|
{ |
75
|
|
|
return 'g-recaptcha-response'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getCollectData () |
79
|
|
|
{ |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
} |