i got it working...somewhat tricky. hope it can help solve ppl's problems.
product.php
FIND
Code: Select all
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
ADD the following code BEFORE it:
Code: Select all
// RECAPTCHA
if (isset($this->request->post['recaptcha_response_field'])) {
$this->data['captcha_response'] = $this->request->post['recaptcha_response_field'];
} else {
$this->data['captcha_response'] = '';
}
if (isset($this->request->post['recaptcha_challenge_field'])) {
$this->data['captcha_challenge'] = $this->request->post['recaptcha_challenge_field'];
} else {
$this->data['captcha_challenge'] = '';
}
REPLACE the old captcha() function with the following function. (it's the same as ppl posted before but put it here for the integrity of the steps.)
Code: Select all
private function recaptcha() {
/* recaptchalib.php needs to be in system/library/ */
$this->load->library('recaptchalib');
// Get a key from https://www.google.com/recaptcha/admin/create
$privatekey = "YOUR PRIVATE KEY";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# was there a reCAPTCHA response?
if ($this->request->post['recaptcha_response_field']) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$this->request->post['recaptcha_challenge_field'],
$this->request->post['recaptcha_response_field']);
if ($resp->is_valid) {
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
return FALSE;
}
then FIND
Code: Select all
if (!$this->request->post['rating']) {
$this->error['message'] = $this->language->get('error_rating');
}
ADD the following code AFTER it
Code: Select all
if (!$this->recaptcha()) {
$this->error['message'] = $this->language->get('error_captcha');
}
SAVE product.php.
open product.tpl
replace
Code: Select all
<input type="text" name="captcha" value="<?php echo $captcha; ?>" autocomplete="off" />
<?php if ($error_captcha) { ?>
<span class="error"><?php echo $error_captcha; ?></span>
<?php } ?>
<br />
<img src="index.php?route=information/contact/captcha" /></td>
with the following
Code: Select all
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=YOUR PUBLIC KEY"></script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=YOUR PUBLIC KEY" 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>
</td>
next replace old javascript review() function (near the bottom of the file)
Code: Select all
function review() {
//...omitted.
}
with
Code: Select all
function review() {
var dataObj = {
'name' : encodeURIComponent($('input[name=name]').val()),
'text' : encodeURIComponent($('textarea[name=text]').val()),
'rating' : encodeURIComponent($('input[name=rating]:checked').val() ? $('input[name=rating]:checked').val() : ''),
'recaptcha_response_field' : encodeURIComponent($('input[name=recaptcha_response_field]').val()),
'recaptcha_challenge_field' : encodeURIComponent($('input[name=recaptcha_challenge_field]').val()),
};
$.ajax({
type: 'POST',
url: 'index.php?route=product/product/write&product_id=<?php echo $product_id; ?>',
data : dataObj,
dataType: 'json',
beforeSend: function() {
$('.success, .warning').remove();
$('#review_button').attr('disabled', 'disabled');
$('#review_title').after('<div class="wait"><img src="catalog/view/theme/default/image/loading_1.gif" alt="" /> <?php echo $text_wait; ?></div>');
},
complete: function() {
$('#review_button').attr('disabled', '');
$('.wait').remove();
},
success: function(data) {
if (data.error) {
$('#review_title').after('<div class="warning">' + data.error + '</div>');
}
if (data.success) {
$('#review_title').after('<div class="success">' + data.success + '</div>');
$('input[name=name]').val('');
$('textarea[name=text]').val('');
$('input[name=rating]:checked').attr('checked', '');
$('input[name=recaptcha_response_field]').val('');
}
}
});
}
product review is submitted differently from inquiries...i.e. via ajax so the form data needs to be added to the ajax request, otherwise they won't be submitted and the validation would constantly fail because it had nothing to check.