2013-10-04 4 views
0

많은 필드가있는 폼이 있는데 그 중 2 개에는 코드가 들어 있습니다. 코드가 일치하지 않는지 확인하고 싶습니다. 다음 요소 :필드에서 유효성 검사기에 다른 필드 추가

  'code1' => array('text', array(
        'required' => true, 
        'label' => 'form-label-code-1', 
        'filters' => array('StringTrim'), 
        'attribs' => array('placeholder' => 'Code 1'), 
        'decorators' => array(
         'ViewHelper', 
         array('HtmlTag', array('tag' => 'div')), 
         'Errors' 
        ), 
        'validators' => array(
         array('Callback', true, array(
           'callback' => array($cservice, 'checkCodesUsed'), 
           'messages' => array(
            Zend_Validate_Callback::INVALID_VALUE => 'form-error-code-exists' 
           ))) 
        ) 
       )), 
      'code2' => array('text', array(
        'required' => true, 
        'label' => 'form-label-code-2', 
        'filters' => array('StringTrim'), 
        'attribs' => array('placeholder' => 'Code 2'), 
        'decorators' => array(
         'ViewHelper', 
         array('HtmlTag', array('tag' => 'div')), 
         'Errors' 
        ), 
        'validators' => array(
         array('Callback', true, array(
           'callback' => array($cservice, 'checkCodesUsed'), 
           'messages' => array(
            Zend_Validate_Callback::INVALID_VALUE => 'form-error-code-exists' 
           ))) 
        ) 
       )), 

현재 콜백은 값이 이미 데이터베이스에 있는지 확인합니다. code1과 code2의 값을 모두 갖는 콜백을 어떻게 지정합니까? 젠드 문서에서 머리를 맞출 수없는 것 같습니다.

답변

0

단순히 콜백 역할을하는 양식 자체에 함수를 추가하여 해결했습니다.

public function checkCodesNotEqual() 
{ 

    if ($this->getElement('code1')->getValue() === $this->getElement('code2')->getValue()){ 
     return false; 
    } 

    return true; 
} 
관련 문제