Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sfWidgetFormReCaptcha patch #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/widget/sfWidgetFormReCaptcha.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class sfWidgetFormReCaptcha extends sfWidgetForm
* * use_ssl: Whether to use SSL or not (false by default)
* * server_url: The URL for the HTTP API
* * server_url_ssl: The URL for the HTTPS API (when use_ssl is true)
* * theme: The ReCaptcha theme
* * culture: The ReCaptcha language
*
* @see sfWidgetForm
*/
Expand All @@ -52,8 +54,10 @@ public function configure($options = array(), $messages = array())
$this->addRequiredOption('public_key');

$this->addOption('use_ssl', false);
$this->addOption('server_url', 'http://api.recaptcha.net');
$this->addOption('server_url_ssl', 'https://api-secure.recaptcha.net');
$this->addOption('server_url', 'http://www.google.com/recaptcha/api');
$this->addOption('server_url_ssl', 'https://www.google.com/recaptcha/api');
$this->addOption('theme', 'clean');
$this->addOption('culture', 'en');
}

/**
Expand All @@ -63,19 +67,28 @@ public function render($name, $value = null, $attributes = array(), $errors = ar
{
$server = $this->getServerUrl();
$key = $this->getOption('public_key');
$theme = $this->getOption('theme');
$culture = $this->getOption('culture');

return sprintf('
<script type="text/javascript">
var RecaptchaOptions = {
theme : \'%s\',
lang : \'%s\'
};
</script>
<script type="text/javascript" src="%s/challenge?k=%s"></script>
<noscript>
<iframe src="%s/noscript?k=%s" height="300" width="500" frameborder="0"></iframe><br />
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge" />
</noscript>
', $server, $key, $server, $key);
', $theme, $culture, $server, $key, $server, $key);
}

protected function getServerUrl()
{
return $this->getOption('use_ssl') ? $this->getOption('server_url_ssl') : $this->getOption('server_url');
}
}