2014-09-22 58 views
0

過濾問題在帳戶表單字段或名和姓用戶註冊頁面的表單字段,當我把下面的JS代碼:表單字段的Magento 1.8.1.0

<script>alert("Here")</script> 

它被保存並運行在頁面加載。這是很奇怪的,因爲我檢查模板文件和值分別如下:轉義:

<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?> 

,如果我在正確的模板文件,通過改變磁場的標籤我也證實。 我已閱讀以下問題,並試圖使用它們,但沒有爲我工作。

https://magento.stackexchange.com/questions/569/how-to-escape-output-data

https://magento.stackexchange.com/questions/8179/is-there-a-generic-way-i-can-apply-input-filtering-to-magento-form-processing

對於觀察者方法,它的工作原理,但是當我嘗試登錄到Magento管理,我不能,但iremove觀察者時,我可以再次登錄。

檢查兩個附加的屏幕截圖。

Form fields where i entered js code

The alert message from the entered js code in the field

請幫助我解決這個問題。

謝謝

回答

0

我創建了一個觀察者。在管理和前端登錄表單(並且可以是一些其它形式的),用戶名和口令表單字段是在陣列格式象下面這樣:

<input type="text" id="username" name="login[username]" value="" class="required-entry input-text"> 

<input type="password" id="login" name="login[password]" class="required-entry input-text" value=""> 

要解決此問題,我已修改代碼中的觀察員如下:

public function sanitizeParams($observer) 
{ 
    if(!Mage::app()->getStore()->isAdmin()) 
    { 
     $post = Mage::app()->getRequest()->getParams(); 
     foreach($post as $pkey => $pvalue) 
     { 
      if(is_array($post[$pkey])) 
      { 
       foreach($post[$pkey] as $key => $value) 
       { 
        $post[$pkey][$key] = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS); 
       } 
      } 
      else 
      { 
       $post[$pkey] = filter_var($pvalue, FILTER_SANITIZE_SPECIAL_CHARS); 
      } 
     } 

     $_POST = $post; 
    } 
} 

它解決了我的問題,現在工作正常。

謝謝。

相關問題