2012-09-25 3 views
3

새로운 Magento 릴리스에서는 "시스템 -> 구성 -> 보안 문자 - 보안 문자"의 보안 문자 옵션을 "Signmeup"이라는 새 양식을 만들었지 만 작동하지 않는 것 같습니다. 표시하는 데 문제가 있습니다.Magento 1.7 보안 문자 모듈

<?php echo Mage::getSingleton('core/layout') 
->createBlock('captcha/captcha_zend') 
->setFormId('signmeup') 
->setImgWidth(230) 
->setImgHeight(50) 
->setTemplate('captcha/zend.phtml') 
->toHtml();?> 

바로 지금 해당 블록이 페이지에 표시되지 않습니다. (아니 동적 페이지 ... 핵심 마법사 부트 업 정적 페이지) 여기 은의 스크린 샷 내가 무엇에 대해 이야기하고 : 온라인 (있는 일부 captcha.xml 코드를 찾은 후

답변

1

이유는 내 회사가 아님), captcha.xml을 생성하고 해당 코드를 레이아웃 폴더에 붙여 넣었습니다.

echo $this->getChildHtml('form.additional.info'); (in php brackets.) 

내가 모든 것을 한 후에 :

다음으로, 나는 내가 보안 문자가 보여주고 싶었다하여 PHTML 파일을 추가 할 수 있었나요 모든이가 admin > Config > Customer config..

에 켜진 것을 확인했다 보여지고 기능적이었다.

+0

안녕, 모든 나는 젠토 커뮤니티 에디션 1.7.0.2을 사용하고 그림과 같이 나는 보안 문자를 사용할 수있다 위 이미지에 나와 있습니다. 그러나 captcha는 프런트 엔드에 표시되지 않습니다. 일부 코드를 변경해야합니까? 제발 도와주세요 – Muk

+0

@Muk, 어떻게 CAPTCHA를 활성화 했습니까? 내 고객 구성에는 보안 문자 옵션이 없으며 마지막 구성 회색 바는 "주소 템플릿"입니다. – johnsnails

0

제품 검토 양식에 기본 captcha 모듈을 추가하는 작은 모듈을 만들어이 작업을 수행 할 수있었습니다. 모듈은 몇 가지 파일로 구성

app/code/local/MyCompany/MyCaptcha/etc/config.xml 
app/code/local/MyCompany/MyCaptcha/Model/Observer.php 
app/etc/modules/MyCompany_MyCaptcha.xml 
app/design/frontend/default/default/layout/mycaptcha.xml 

당신이에 보안 문자를 추가 할 양식이 포함 된 템플릿 (로 .phtml) 파일에 다음 코드를 추가합니다 :

<?php echo $this->getLayout()->createBlock('captcha/captcha') 
->setFormId('your_form_id') 
->setImgWidht(230) 
->setImgHeight(50) 
->toHtml(); 
?> 

변화를 'your_form_id' 네가 원하는대로
config.xml에 에서 : config.xml에 그것을이다

<config> 
    <modules> 
     <MyCompany_MyCaptcha> 
      <version>1.0.0</version> 
     </MyCompany_MyCaptcha> 
    </modules> 
    <frontend> 
     <layout> 
      <updates> 
       <mycaptcha> <!-- should be some unique name --> 
        <file>mycaptcha.xml</file> 
       </mycaptcha> 
      </updates> 
     </layout> 
    </frontend> 
    <!-- Now we need to add our observer. I attached mine to the 
controller_action_predispatch_review_product_post event because 
I needed to intercept product review post event. The event you 
attach your observer to will be different depending on what you're 
trying to do. --> 
    <global> 
     <events> 
      <controller_action_predispatch_review_product_post> 
       <observers> 
        <mycaptcha> <!-- these need to match --> 
         <class>MyCompany_MyCaptcha_Model_Observer</class> 
         <method>myMethod</method> 
        </mycaptcha> 
       </observers> 
      </controller_action_predispatch_review_product_post> 
     </events> 
    </global> 
    <!-- Now we add our form label that will show in configuration and allow 
us to turn the captcha on or off. --> 
    <default> 
     <captcha> 
      <frontend> 
       <areas> 
        <mycaptcha> <!-- these need to match --> 
         <label>My Captcha</label> 
        </mycaptcha> 
       </areas> 
      </frontend> 
     </captcha> 
    </default> 
</config> 


는 이제 우리의 옵저버를 추가 할 수 있습니다. 다음 코드는 http://mustakarhu.com/blog/magento-captcha-extension-ajax/에서 약간 변경되었으므로 큰소리로 외쳤습니다.

<?php 
/** 
* Break the execution in case of incorrect CAPTCHA 
* 
* @param Varien_Event_Observer $observer 
* @return Cbad_Captcha_Model_Observer 
*/ 

class MyModule_MyCaptcha_Model_Observer extends Mage_Captcha_Model_Observer 
{ 

public function myMethod($observer) { // called in config.xml 
    $formId = 'your_form_id'; // you will change this value 
    $captchaModel = Mage::helper('captcha')->getCaptcha($formId); 
    $controller = $observer->getControllerAction(); 
    $request = $controller->getRequest(); 
    if ($captchaModel->isRequired()) { 

     $request->getPost(Mage_Captcha_Helper_Data::INPUT_NAME_FIELD_VALUE); 
     if (!$captchaModel->isCorrect($this->_getCaptchaString($request, $formId))) { 

      if((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) { 
       // Is ajax 
       $action = $request->getActionName(); 
       Mage::app()->getFrontController()->getAction()->setFlag(
         $action, Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); 

       $controller->getResponse()->setHttpResponseCode(200); 
       $controller->getResponse()->setHeader('Content-type', 'application/json'); 

       $controller->getResponse()->setBody(json_encode(
         array(
          "msg" => Mage::helper('captcha')->__('Incorrect CAPTCHA.') 
         ) 
        )); 

      } else { 
       // Is form submit 
       Mage::getSingleton('customer/session') 
        ->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); 
       $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); 
       Mage::getSingleton('customer/session') 
        ->setCustomerFormData($controller->getRequest()->getPost()); 
       $controller->getResponse()->setRedirect(Mage::getUrl('*/*')); 
      } 
     } 
    } 

    return $this; 
    } 
} 
?> 

대부분의 작업이 방해가됩니다. 나는 너만 알아볼 수 있도록 MyCompany_MyCaptcha.xml을 남겨 둘 것이다 (매우 간단하다).
mycaptcha.xml 상에, :

<?xml version="1.0"?> 
<layout version="0.1.0"> 
<catalog_product_view> 
     <reference name="head"> 
      <action method="addJs"><file>mage/captcha.js</file></action> 
     </reference> 
</catalog_product_view> 
</layout> 

이 레이아웃 XML은 제품 페이지의 헤드 섹션에 필요한 자바 스크립트를 추가합니다. 레이아웃 핸들 (catalog_product_view)을 양식이있을 페이지로 변경해야합니다.
나는 모든 것을 충분히 자세히 다루었 고 누군가가 자신의 필요에 맞게이를 적용 할 수 있기를 바랍니다.이 주제에

일부 다른 자원 :