2011-07-29 6 views
4

Magento에는 서버 측 형식 검증이 있습니까? 나는에서 만든 및 magentos 양식 유효성 검사를 사용하지만 누군가가 javascipt를 해제하고 유해한 수있는 뭔가를 입력하면 작동하지 않을거야. 거기에 클래스가없는 경우. 누군가가 백업으로 서버 측 양식 유효성 검사를 구현하는 방법을 알려주 길 바랍니다. 여기 내 내 코드 형태Magento 서버 측 형식 유효성 확인

<div style="border:0px solid red; margin:0px auto;"> 

<?php $_product = $this->getProduct(); ?> 


<form id="test" action="<?php echo Mage::getUrl('pricenotify/pricenotify/db') ?>" method="post"> 

      <label for="price">Price *</label> 
      <input type="text" id="price" name="price" value="" class="required-entry validate-number"/><br /> 
      <label for="email">Email Address *</label> 
      <input type="text" id="email" name="email" value="" class="required-entry validate-email"/> 
      <input type="hidden" id="id" name="id" value="<?php echo $_product->getId() ?>" /> 
      <input type="hidden" id="propri" name="propri" value="<?php echo $_product->getPrice() ?>" /> 

      <input type="submit" name="submit" value="<?php echo $this->__('Submit') ?>" onclick="if(customForm.validator && customForm.validator.validate()) this.form.request(); return false;" /> 

</form> 

<script type="text/javascript"> 
//< ![CDATA[ 
var customForm = new VarienForm('test',false); 
//]]> 
</script> 

답변

-4

젠토 양식을 검증하기 위해 프로토 타입을 사용을위한 것입니다. 이 유효성 검사를 구현하려면 입력 태그에 "required-entry"를 추가하기 만하면됩니다.

+8

OP는 명시 적으로 서버 측 유효성 검사를 요구합니다. 프로토 타입은 js와 클라이언트 측 (그리고 실제로 ** ** 안전하지 않음)입니다. –

3

예, Magento는 일부 양식에 대해 서버 측 유효성 검사를 수행합니다. 그러나 폼을 추가 한 모듈은 폼의 유효성을 검사합니다. 따라서 플러그인과 같은 타사 코드를 처리하는 경우 폼이 없을 수 있습니다.

일반적으로 유효성 검사 코드는 모듈의 Model 부분과 함께 존재합니다. 예를 들어 Magento의 기본 검토 기능에서 검토 양식을 제출하면 해당 데이터는 /app/code/core/Mage/Review/Model/Review.php 파일의 validate() 함수에 의해 유효성이 검사됩니다. 먼저 해당 코드와 기존 Mage/Core 모듈의 코드를 예제로 살펴 보겠습니다. 당신은 간단하게 유지하려면

당신이주는 상황에서

, 검증 논리에 대한 기존의 장소는 당신이 당신의 컨트롤러

try { 
      $postObject = new Varien_Object(); 
      $postObject->setData($post); 

      $error = false; 

      if (!Zend_Validate::is($postObject->getPrice(), 'NotEmpty')) { 
       $error = true; 
      } 

      if (!Zend_Validate::is($postObject->getEmail(), 'EmailAddress')) { 
       $error = true; 
      } 

      if ($error) { 
       throw new Exception(); 
      } 


      //save to db 

      return; 
     } catch (Exception $e) { 
      Mage::getSingleton('customer/session')->addError(Mage::helper('pricenotify')->__('Unable to submit your request. Please, try again later')); 
      $this->_redirect('/'); 

      return; 
     } 

Zend_Validate의 유효성 검사를 할 수있는, /app/code/local/YourCompany/PriceNotify/Model/Pricenotify.php

관련 문제