동적으로 확장 가능한 zend 양식에 대한 도움이 필요합니다.동적으로 확장 가능한 zend 양식 유효성 검사 및 렌더링 방법
<form>
<fieldset class="itemGroup">
<label>
Question
<input type="text" name="items[questions][]" value="">
</label>
<label>
Answer
<input type="text" name="items[answers][]" value="">
</label>
</fieldset>
</form>
나는 다음과 같은 절차를 얻을 :
나는 두 가지 요소가 포함 된 하위 폼과 양식을 가지고
$itemsSubform = new Zend_Form_SubForm();
$form->addSubForm($itemsSubform, 'items');
$itemsSubform->setElementsBelongTo('items');
$itemQuestion = new Zend_Form_Element_Text('questions', array(
'label' => 'Question',
'isArray' => true,
'filters' => array(
'stringTrim',
),
'validators' => array(
array('stringLength', array('max' => 255)),
),
));
$itemAnswer = new Zend_Form_Element_Text('answers', array(
'label' => 'Answer',
'isArray' => true,
'filters' => array(
'stringTrim',
),
'validators' => array(
array('stringLength', array('max' => 255)),
),
));
$itemsSubform->addDisplayGroup(array($itemQuestion, $itemAnswer), 'itemGroup');
필요한 경우, 난 그냥 자바 스크립트로 폼을 확장에 대한 모든 필드 셋을 복사 .
양식을 제출할 때까지 모두 올바르게 작동합니다. 유효성 검사를하는 동안 아무 요소도 유효성을 검사하지 않으며, 렌더링 양식 중에 이러한 데이터로 채워지면 Zend_View_Abstract 클래스에서 이스케이프 값이 문자열 대신 배열임을 알리는 오류 메시지가 표시됩니다.이 메서드는 해당 값을 이스케이프 처리하기 위해 요소를 렌더링하는 동안 호출됩니다.
compltion의 경우, $ form-> getValues (); 형성하기 위해 행동
Array
(
[items] => Array
(
[questions] => Array
(
[0] => lorem
[1] => dolor
)
[answers] => Array
(
[0] => ipsum
[1] => sit
)
)
)
사람이 어떻게 나에게 조언을 할 수
: 확인 후, 나는이 얻을 (자바 스크립트에 의해 다른 필드 셋이 추가됩니다)? 이상적인 해결책은 양식 자체가 각 값을 개별적으로 검증하고 fieldset (displayGroup)을 렌더링해야하는 횟수를 찾는 것입니다.