2016-06-08 1 views
0

필드 이름이 배열에있는 양식 필드에서 유효성 검사를 수행하는 방법을 알아 내려고하고 있습니다. 나는에 문제가 있어요 필드 이름은이 형식으로되어 있습니다 :Zend 2 폼 유효성 검사 - 배열 필드 이름

'idNumber' => string '' (length=0) 
    'phone' => string '' (length=0) 
    'campus' => string '10427' (length=5) 
    'item' => 
    array (size=1) 
     1 => 
     array (size=6) 
      'ILLType' => string 'book' (length=4) 
      'requiredBy' => string '' (length=0) 
      'urgent' => string '0' (length=1) 
      'citation' => string '' (length=0) 
      'getFrom' => string '' (length=0) 
      'copyright' => string '0' (length=1) 
    'captcha' => 
    array (size=2) 
     'id' => string 'f0b53b625adad9371eafb7ee0b2e171b' (length=32) 
     'input' => string '' (length=0) 
    'submit' => string 'Submit ILL' (length=10) 

나는 문제없이이 없습니다 : item[1][urgent]이 필드를 통해 여기 오는 형태가 유효성 검사를 통해 넣어 직전 데이터의 형식입니다 양식 필드 (즉 idNumber, 캠퍼스) ''배열 내에서 유효성 검사를하는 데 문제가 있습니다. 내가 한 방식을 검증하는 좋은 방법이 있습니까? 여기에 관련 코드 :

형태 :

$idNumber = new Element\Text('idNumber'); 
$idNumber->setLabel('* Your Deakin Library Borrower Number') 
          ->setLabelAttributes(array('class' => 'sq-form-question-title')) 
          ->setAttribute('summary', '(14 digit barcode number at the bottom of student/staff ID):') 
          ->setAttribute('class', 'sq-form-field required') 
          ->setAttribute('id', 'idNumber'); 



$ILLType = new Element\Select('item[1][ILLType]'); 
$ILLType->setLabel('* What is your request about?') 
       ->setLabelAttributes(array('class' => 'sq-form-question-title')) 
       ->setAttribute('class', 'sq-form-field required request_type') 
       ->setAttribute('id', 'ILLType_1') 
       //->setAttribute('multiple', 'multiple') 
       ->setOptions($ILLTypes); 



$urgent = new Element\Checkbox('item[1][urgent]'); 
$urgent->setLabel('Urgently required?') 
     ->setLabelAttributes(array('class' => 'sq-form-question-title')) 
     ->setAttribute('class', 'sq-form-field') 
     ->setAttribute('id', 'urgent_1'); 

폼 필터 :

$idNumber = new Input('idNumber'); 
$idNumber->getValidatorChain() 
     ->addByName('NotEmpty');     


$ILLType = new Input('item[1][ILLType]'); 
$ILLType->getValidatorChain() 
     ->addByName('InArray', array('haystack' => array_keys(
            $ILLTypes['options'] 
           ))); 
$ILLType->getFilterChain() 
     ->attach(new Filter\StringToLower()) 
     ->attachByName('StripTags'); 

PostController :

 $this->ILLForm->prepareElements($this->ILLCategories, $this->campuses, $this->getFromOptions); 
     // Assign POST data to form 
     $this->ILLForm->setData($data); 

     $this->ILLFormFilter->prepareFilters($this->ILLCategories, $this->campuses, $this->getFromOptions); 
     $this->ILLForm->setInputFilter($this->ILLFormFilter); 

     if (!$this->ILLForm->isValid($data)) { 

      $this->flashMessenger()->addMessage('Please ensure you have filled in all the required fields'); 
     } 

답변

1

같은 배열 요소에 대한 특별한 Zend\Form\Element\Collection 클래스가 있습니다. 이 클래스의 전체 ZF2 문서에 대한

확인 내가 찾던 무엇 장 Collection

+0

! 감사 – adamst85