2013-03-09 21 views
0

我是Magento的新手,我接受了創建擴展的任務。在Magento模塊中發佈表單時出錯?

我正在閱讀文章並繼續前進。

到目前爲止,我可以在管理部分的主導航中添加我的菜單,並在該菜單上調用Controller並加載我的.phtml文件的View

現在我在我的.phtml文件上有一個表格,我在同一個控制器上發佈但是在不同的功能上,而不是調用那個功能它要去儀表板。我檢查了表單動作,它很完美,但仍然沒有調用該函數。

以下是我的Controller的代碼。

class Gwb_Magecrmsync_Adminhtml_CustomersController extends Mage_Adminhtml_Controller_Action 
{ 
public function indexAction() 
{ 
    $this->loadLayout() 
     ->_setActiveMenu('menu1') 
     ->_addBreadcrumb(Mage::helper('adminhtml')->__('Synchronize Data'), Mage::helper('adminhtml')->__('Synchronize Data')) 
     ->_title($this->__('Synchronize Data')); 

    $block = $this->getLayout()->createBlock(
     'Mage_Core_Block_Template', 
     'my_block_name_here', 
     array('template' => 'magecrmsync/customers.phtml') 
    ); 
    $this->getLayout()->getBlock('content')->append($block); 

    $this->renderLayout(); 

} 

public function authenticationAction() 
{ 
    if($this->getRequest()->getPost()) 
    { 
     try 
     { 
      $username = $this->getRequest()->getPost('username'); 
      $password = $this->getRequest()->getPost('password'); 

     // validate user here 
     } 
     catch(Exception $e) 
     { 
      Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 
      return; 
     } 
    } 
    else 
    { 
     echo "NO"; 
    } 
    //$this->_redirect('*/*/'); 
} 

}

下面是我的customers.phtml文件代碼:

<form action="<?php echo Mage::getUrl('*/*/authentication'); ?>" method="post"> 
    <fieldset> 
<ul> 
<li> 
    <label for="username">Username</label> 
    <input type="text" id="username" name="username" /> 
</li> 
<li> 
    <label for="password">Password</label> 
    <input type="password" id="password" name="password" /> 
</li> 
<li> 
    <input type="submit" name="authenticate" id="authenticate" value="Authenticate" /> 
</li> 
    </ul> 
</fieldset> 
</form> 

請告訴我,我在做什麼錯在這裏。

任何幫助將非常感激,並會對我有幫助。

謝謝

回答

0

您需要添加一個密鑰到表單以保證安全性,否則它將無法工作。這種添加到您的形式,它應該工作:)

<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" /> 
+0

您好安德魯,當我把這個隱藏字段到表單,該值是空白的,它是沒有得到形式鍵。你能告訴我爲什麼嗎? – 2013-03-11 10:03:17

+0

看看這個:http://www.spinonesolutions.com/2011/01/admin-form-post-form_key/ – Andrew 2013-03-11 10:08:19

+0

我剛剛看到,但我不明白爲什麼在我的表格中,鍵是空白的? – 2013-03-11 10:10:08