2012-07-21 61 views
0

我有一個zend表單的問題,我需要在其中字段名稱相同但具有不同所有物的情況下構建表單。這是我想要的表單中的輸入字段。具有相同名稱但具有不同所有物的zend框架文本字段

目前我正在用直html,但因爲這我缺少驗證。

<input type="text" name="travel_guide_tab[4][title]"> 
<input type="text" name="travel_guide_tab[4][description]"> 
<input type="text" name="travel_guide_tab[6][title]"> 
<input type="text" name="travel_guide_tab[6][description]"> 
+0

請進一步解釋您如何驗證。如果您使用客戶端驗證,您可以在服務器端進行驗證。 – 2012-07-21 16:37:06

回答

0

在Zend中表單元素名稱必須是唯一的(以某種方式),否則它們將被覆蓋。但是,您可以繼續使用您的html表單,並使用Zend_Filter_Input在控制器中進行篩選和驗證。 filtervalidation類與Zend_Form使用的類相同,只是以不同的方式傳遞數據。
簡單的例子,局部:

public function someAction() { 
     //set filters and validators for Zend_Filter_Input 
     $filters = array(
      'nameOfInput' => array('HtmlEntities', 'StripTags') 
     ); 
     $validators = array(
      'nameOfInput' => array('NotEmpty', 'Int') 
     ); 
     //assign Input 
     $input = new Zend_Filter_Input($filters, $validators);//can also pass the data in constructor (optional) 
     $input->setData($this->getRequest()->getParams()); 
      //check input is valid and is specifically posted as 'Delete Selected' 
      if ($input->isValid()) { 
      //do some stuff 
      } 

好運。

相關問題