2012年2月14日 星期二

對joomla 1.5的「聯絡我們」加入recapthca的作法

細節前面已談過,只要真的看懂前面的文章,就一定會的,所以這邊僅就該改的檔案即其改的位置提出:

分別為components/com_contact/views/contact/tmpl/default_form.php

與components/com_contact/controller.php

這兩個檔案,前者是放入

<?php
//底下是發哥自己加入的
?>
<div align="center">請於下列欄位中輸入下圖所見之驗證碼</div>
<div align="right"><?php
require_once('recaptchalib.php');
          $publickey = "你的公開鑰匙"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
<?php
//以上是哥發自己加入的
?>

後者放入

//
  require_once('recaptchalib.php');
  $privatekey = "你的私人密鑰";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("你輸入的驗證碼錯誤,請回上一頁再試一次!" .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }

//

前者放在:

<button class="button validate" type="submit"><?php echo JText::_('Send'); ?></button>

之前而成為:

<?php
//底下是發哥自己加入的
?>
<div align="center">請於下列欄位中輸入下圖所見之驗證碼</div>
<div align="right"><?php
require_once('recaptchalib.php');
          $publickey = "你的公開鑰匙"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
<?php
//以上是哥發自己加入的
?>

<button class="button validate" type="submit"><?php echo JText::_('Send'); ?></button>

後者放在:

function submit()
       {
               global $mainframe;

               // Check for request forgeries
               JRequest::checkToken() or jexit( 'Invalid Token' );

       $useSecurityImagesInContact = false;
                       if (file_exists(JPATH_SITE.DS."administrator".DS."components".DS."com_securityimages".DS."config.securityimages.php")) {
               include(JPATH_SITE.DS."administrator".DS."components".DS."com_securityimages".DS."config.securityimages.php");
               $useSecurityImagesInContact = $securityImagesInContact;
           }

 

之後,而成為:

function submit()
       {
               global $mainframe;

               // Check for request forgeries
               JRequest::checkToken() or jexit( 'Invalid Token' );

       $useSecurityImagesInContact = false;
                       if (file_exists(JPATH_SITE.DS."administrator".DS."components".DS."com_securityimages".DS."config.securityimages.php")) {
               include(JPATH_SITE.DS."administrator".DS."components".DS."com_securityimages".DS."config.securityimages.php");
               $useSecurityImagesInContact = $securityImagesInContact;
           }

 

//
  require_once('recaptchalib.php');
  $privatekey = "你的私人密鑰";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("你輸入的驗證碼錯誤,請回上一頁再試一次!" .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }

//

存檔完即可。

特別再強調recaptchalib.php的路徑必須指對!路徑若錯,找不到檔案的話,一切就沒用了!

沒有留言: