2012-04-18 64 views
3

我以爲我有這個排序,但我遇到了一個障礙。我想在客戶註冊表中添加一個「蜂蜜罐」,因爲那些不熟悉的技巧涉及到使用CSS隱藏文本輸入,並假定一般的機器人將要填充它。然而,人類不會看到該領域,所以它需要驗證爲空。Magento客戶註冊'蜂蜜罐'驗證碼

在Magento我創建了一個新的模塊,添加了以下到config.xml:

<global> 
    <fieldsets> 
     <customer_account> 
      <honeytrap><create>1</create><update>1</update></honeytrap> 
     </customer_account> 
    </fieldsets> 
    <models> 
     <customer> 
      <rewrite> 
       <customer>MyStore_Honeytrap_Model_Customer</customer> 
      </rewrite> 
     </customer> 
    </models> 
</global> 

我,然後加入一點點額外的驗證功能來檢查該字段爲空。這一切都正確,據我所知,但line 278AccountController.phpextractData()丟棄輸入字段從請求中的發佈數據。我對Magento仍然很陌生,所以希望能在這裏學到一些東西,但是如何防止extractData()被剝離出來?

猜猜我只想知道我錯過了什麼,我已經在網上閱讀了一些關於添加自定義字段的文章,據我所知這應該是工作,但也許我已經錯過了一些東西我沒有包含實體設置,因爲我不需要在數據庫中保存這個字段,它純粹是爲了驗證註冊來自人(儘可能)。

感謝您的任何幫助,我敢肯定這可能是我錯過了一些荒謬的事情。

編輯:感謝@戈登 - knoppe指針上使用事件:在​​3210

public function check_trap(Varien_Event_Observer $observer) 
{ 
    $event = $observer->getEvent(); 
    $post = $event->getControllerAction()->getRequest()->getPost(); 

    // Check Honeytrap is empty 
    if (Zend_Validate::is(trim($post['fname']) , 'NotEmpty')) 
    { 
     $customerHelper = Mage::helper('customer'); 
     $error = $customerHelper->__('A problem has occured with your registration.'); 
     Mage::getModel('customer/session')->addError($error); 

     Mage::app()->getResponse() 
      ->setRedirect(Mage::getUrl('customer/account', array('_secure' => true))) 
      ->sendResponse(); 
     exit; 
    } 
} 

有了這個:

<events> 
     <controller_action_predispatch_customer_account_createpost> 
      <observers> 
       <mystore_honeytrap_observer> 
        <type>singleton</type> 
        <class>Mystore_Honeytrap_Model_Observer</class> 
        <method>check_trap</method> 
       </mystore_honeytrap_observer> 
      </observers> 
     </controller_action_predispatch_customer_account_createpost> 
    </events> 

回答

3

來處理,這可能是一個更超然的方式在相關控制器動作(controller_action_predispatch_*)之前註冊一個觀察者以檢測您的表單字段是否已填充,如果是,則將其重定向以阻止永久處理本機操作請求。

+0

我已編輯我的帖子,以反映我的實驗,而不是使用事件。它的工作原理雖然我確實有一點與重定向的爭鬥,所以有可能有更好的/更清潔的方式來做到這一點。感謝您的指示:) – createdbypete 2012-04-19 11:08:52