| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
class sfFormReCaptcha extends sfForm |
|---|
| 30 |
{ |
|---|
| 31 |
|
|---|
| 32 |
* @see sfForm |
|---|
| 33 |
*/ |
|---|
| 34 |
public function __construct($defaults = array(), $options = array(), $CSRFSecret = null) |
|---|
| 35 |
{ |
|---|
| 36 |
parent::__construct($defaults, $options, $CSRFSecret); |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
// called in __construct() so we can append the captcha field to the whole form. |
|---|
| 40 |
$this->setupCaptcha(); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
* Bind parameters, including the captcha ones, from a sfRequest object instance |
|---|
| 45 |
* |
|---|
| 46 |
* @param sfRequest A sfRequest instance |
|---|
| 47 |
* |
|---|
| 48 |
* @return Boolean true if the form is valid, false otherwise |
|---|
| 49 |
*/ |
|---|
| 50 |
public function bindFromRequest(sfRequest $request) |
|---|
| 51 |
{ |
|---|
| 52 |
$nameFormat = $this->widgetSchema->getNameFormat(); |
|---|
| 53 |
|
|---|
| 54 |
if ('%s' == $nameFormat) |
|---|
| 55 |
{ |
|---|
| 56 |
throw new LogicException('You must define a name format using setNameFormat() in order to use the bindFromRequest() method'); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
$nameFormat = substr($nameFormat, 0, strpos($nameFormat, ('['))); |
|---|
| 60 |
|
|---|
| 61 |
$params = $request->getParameter($nameFormat, array()); |
|---|
| 62 |
if (true === sfConfig::get('app_recaptcha_enabled')) |
|---|
| 63 |
{ |
|---|
| 64 |
$captcha = array( |
|---|
| 65 |
'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), |
|---|
| 66 |
'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'), |
|---|
| 67 |
); |
|---|
| 68 |
$params = array_merge($params, array('captcha' => $captcha)); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
return parent::bind($params); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
* Setup captcha for current form |
|---|
| 76 |
* |
|---|
| 77 |
*/ |
|---|
| 78 |
protected function setupCaptcha() |
|---|
| 79 |
{ |
|---|
| 80 |
if (true === sfConfig::get('app_recaptcha_enabled')) |
|---|
| 81 |
{ |
|---|
| 82 |
$this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array('public_key' => sfConfig::get('app_recaptcha_public_key'))); |
|---|
| 83 |
$this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array('private_key' => sfConfig::get('app_recaptcha_private_key'))); |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|