1

我有一个插入3个子表单的表单。如果需要,我可以发布它如何构建这些子表单的代码,但由于它非常庞大,所以我只在这里放置最相关的部分。带有子表单的Zend Form导致提交按钮停止工作

首先形式的init()功能:

public function init() { 

     $redirect = new Zend_Form_Element_Hidden('redirect'); 

     $categories = new HPU_Form_Element_TreeView('tree'); 
     $categories->setMultiOptions($this->categoryList); 
     $categories->setLabel('Home') 
        ->setValue($this->selectedCategoryList) 
        ->setRequired(true); 

     $id = new Zend_Form_Element_Hidden('id'); 
     $id->addFilter('Int'); 

     $title = new Zend_Form_Element_Text('title'); 
     $title->setLabel('Title') 
       ->setRequired(true); 

     $subtitle = new Zend_Form_Element_Text('subtitle'); 
     $subtitle->setLabel('Subtitle') 
        ->setRequired(true); 

     $language_id = new Zend_Form_Element_Select("language_id"); 
     $language_id->setLabel('Language') 
        ->setRequired(true) 
        ->addMultiOption("" , "Choose a language"); 

     $table = new Content_Model_DbTable_Language(); 
     foreach ($table->fetchAll() as $language) { 
      $language_id->addMultiOption($language->id, $language->name); 
     } 

     $start_date = new ZendX_JQuery_Form_Element_DatePicker('start_date'); 
     $start_date->setLabel('Start date') 
        ->setValue(date('j-m-Y')) 
        ->setRequired(true) 
        ->setAttrib('jQueryParams', array('dateFormat' => 'dd-mm-yy')); 

     $expiration_date = new ZendX_JQuery_Form_Element_DatePicker('expiration_date'); 
     $expiration_date->setLabel('Expiration date') 
         ->setAttrib('jQueryParams', array('dateFormat' => 'dd-mm-yy')); 

     $status = new Zend_Form_Element_Select("status"); 
     $status->setLabel('Status') 
       ->setRequired(true) 
       ->addMultiOptions(array("1" => "Concept", "2" => "Ready to publish", "3" => "Published", 
       "4" => "Offline")); 

     $meta_description = new Zend_Form_Element_Textarea('meta_description'); 
     $meta_description->setLabel('Meta description') 
          ->setAttrib('rows', '4'); 

     $meta_keywords = new Zend_Form_Element_Textarea('meta_keywords'); 
     $meta_keywords->setLabel('Meta keywords') 
         ->setAttrib('rows', '4'); 

     $introductory_text = new HPU_Form_Element_Tinymce('introductory_text'); 
     $introductory_text->setLabel('Introductory text'); 

     $content_text = new HPU_Form_Element_Tinymce('content_text'); 
     $content_text->setLabel('Follow up text'); 

     $submit_button = new Zend_Form_Element_Submit('submit_button'); 

     $this->setDecorators(array('ViewHelper')); 
     $this->setElementDecorators(array('ViewHelper')); 
     $this->setDecorators(array('FormElements', 'Form')); 

     $this->addElements(array($redirect, $categories, $id, $title, $subtitle, $language_id, $start_date, $expiration_date, $status)); 

     $this->addEnclosedItems(); 
     $this->addEyecatcher(); 
     $this->addYoutubeItems(); 

     $this->addElements(array($meta_description, $meta_keywords, $introductory_text, $content_text, $submit_button)); 

    } 

正如你可以看到,我宣布了一些元素,然后使用addElements()功能,将它们添加到窗体。然而,因为我希望我的3子窗体(这是由各自的职能addEnclosedItems()addYoutubeItems()addEyecatchers()再创造了我添加元素的最后一部分,我已经分手这件事分成两个部分。

结果我得到以下HTML:

<form id="content" enctype="multipart/form-data" action="" method="post"> 

<dt id="redirect-label">&#160;</dt> 

<dd id="redirect-element"> 

<input type="hidden" name="redirect" value="" id="redirect" /></dd> 

<dt id="tree-label"><label for="tree" class="required">Home</label></dt> 

<dd id="tree-element"> 

<ul id="tree"><li><input value="72" id="tree-72" name="tree[]" type="hidden" /><label for="tree-72" class="parent">Test Categorie 1</label><ul id="tree"><li><input checked="checked" value="75" id="tree-75" name="tree[]" type="checkbox" /><label for="tree-75" class="child">Test Categorie 1.1</label></li><li><input value="76" id="tree-76" name="tree[]" type="checkbox" /><label for="tree-76" class="child">Test Categorie 1.2</label></li></ul></li><li><input value="73" id="tree-73" name="tree[]" type="hidden" /><label for="tree-73" class="parent">Test Categorie 2</label><ul id="tree"><li><input value="77" id="tree-77" name="tree[]" type="hidden" /><label for="tree-77" class="parent">Test Categorie 2.1</label><ul id="tree"><li><input value="80" id="tree-80" name="tree[]" type="checkbox" /><label for="tree-80" class="child">Test category 2.1.1</label></li></ul></li><li><input checked="checked" value="78" id="tree-78" name="tree[]" type="checkbox" /><label for="tree-78" class="child">Test Categorie 2.2</label></li><li><input value="79" id="tree-79" name="tree[]" type="checkbox" /><label for="tree-79" class="child">Test Categorie 2.3</label></li></ul></li><li><input value="74" id="tree-74" name="tree[]" type="checkbox" /><label for="tree-74" class="child">Test Categorie 3</label></li><li><input value="86" id="tree-86" name="tree[]" type="hidden" /><label for="tree-86" class="parent">Test Category 4</label><ul id="tree"><li><input value="87" id="tree-87" name="tree[]" type="checkbox" /><label for="tree-87" class="child">Test Category 4.1</label></li></ul></li></ul></dd> 

<dt id="id-label">&#160;</dt> 

<dd id="id-element"> 

<input type="hidden" name="id" value="57" id="id" /></dd> 

<dt id="title-label"><label for="title" class="required">Title</label></dt> 

<dd id="title-element"> 

<input type="text" name="title" id="title" value="Test Content 2" /></dd> 

<dt id="subtitle-label"><label for="subtitle" class="required">Subtitle</label></dt> 

<dd id="subtitle-element"> 

<input type="text" name="subtitle" id="subtitle" value="Test Content 2" /></dd> 

<dt id="language_id-label"><label for="language_id" class="required">Language</label></dt> 

<dd id="language_id-element"> 

<select name="language_id" id="language_id"> 
    <option value="" label="Choose a language">Choose a language</option> 
    <option value="1" label="Dutch" selected="selected">Dutch</option> 
    <option value="2" label="Russian">Russian</option> 
</select></dd> 

<dt id="start_date-label"><label for="start_date" class="required">Start date</label></dt> 

<dd> 

<input type="text" name="start_date" id="start_date" value="0000-00-00 00:00:00" /></dd> 

<dt id="expiration_date-label"><label for="expiration_date" class="optional">Expiration date</label></dt> 

<dd> 

<input type="text" name="expiration_date" id="expiration_date" value="0000-00-00 00:00:00" /></dd> 

<dt id="status-label"><label for="status" class="required">Status</label></dt> 

<dd id="status-element"> 

<select name="status" id="status"> 
    <option value="1" label="Concept" selected="selected">Concept</option> 
    <option value="2" label="Ready to publish">Ready to publish</option> 
    <option value="3" label="Published">Published</option> 
    <option value="4" label="Offline">Offline</option> 
</select></dd> 

<dt id="enclosedItem-label">&#160;</dt><dd id="enclosedItem-element"><fieldset id="fieldset-enclosedItem"><dl> 

<dt id="addEnclosedItem-label">&#160;</dt><dd id="addEnclosedItem-element"> 

<button name="enclosedItem[addEnclosedItem]" id="enclosedItem-addEnclosedItem" type="button">add enclosed item</button></dd></dl></fieldset></dd> 

<div class="eyecatcher_item"><form id="eyecatcher" enctype="application/x-www-form-urlencoded" action="" method="post"> 

<dt id="eyecatcher-eyecatcher-label">&#160;</dt> 

<dd id="eyecatcher-eyecatcher-element"> 

<img src='/fm/Tulips.jpg'/></dd> 

<dt id="deleteEyecatcher59-label">&#160;</dt><dd id="deleteEyecatcher59-element"> 

<button name="eyecatcher[deleteEyecatcher59]" id="eyecatcher-deleteEyecatcher59" type="button" class="delete" itemid="59">delete</button></dd></form></div> 

<dt id="youtube-label">&#160;</dt><dd id="youtube-element"><fieldset id="fieldset-youtube"><dl> 

<dt id="addYoutube-label">&#160;</dt><dd id="addYoutube-element"> 

<button name="youtube[addYoutube]" id="youtube-addYoutube" type="button">add youtube item</button></dd></dl></fieldset></dd> 

<dt id="meta_description-label"><label for="meta_description" class="optional">Meta description</label></dt> 

<dd id="meta_description-element"> 

<textarea name="meta_description" id="meta_description" rows="4" cols="80"></textarea></dd> 

<dt id="meta_keywords-label"><label for="meta_keywords" class="optional">Meta keywords</label></dt> 

<dd id="meta_keywords-element"> 

<textarea name="meta_keywords" id="meta_keywords" rows="4" cols="80"></textarea></dd> 

<dt id="introductory_text-label"><label for="introductory_text" class="optional">Introductory text</label></dt> 

<dd id="introductory_text-element"> 

<textarea name="introductory_text" id="introductory_text" class="tinyMCE" rows="24" cols="80"></textarea></dd> 

<dt id="content_text-label"><label for="content_text" class="optional">Follow up text</label></dt> 

<dd id="content_text-element"> 

<textarea name="content_text" id="content_text" class="tinyMCE" rows="24" cols="80"></textarea></dd> 

<dt id="submit_button-label">&#160;</dt><dd id="submit_button-element"> 

<input type="submit" name="submit_button" id="submit_button" value="Save" /></dd></form> 

到目前为止,所不同的是,因为我添加子窗体,将不再提交的作品完美

任何人碰巧知道/看是什么问题的任何意见,将不胜感激。? )

更新: 我更新了适当扩展Zend_Form_Subform后返回的HTML代码。我也已经能够发现问题在addEyecatcher函数中的某处,因为只要这个函数没有执行,窗体就会工作。

下面是创建窗体上addEyecatcher功能:

公共职能addEyecatcher(){$ = eyecatcher_form新Zend_Form_SubForm的();

if(!$this->eyecatcher_image) { 
    $eyecatcher = new Zend_Form_Element_File('eyecatcher'); 
    $eyecatcher->setLabel('Eyecatcher') 
        ->addValidator('Extension', false, 'jpg') 
        ->setDestination(Zend_Registry::get('config')->content->tempFysicalLocation); 
    $eyecatcher_form->addElement($eyecatcher); 
} else { 
    $this->addPrefixPath('HPU_Form_Element', 'HPU/Form/Element/', 'Element'); 
    $eyecatcher = new HPU_Form_Element_Note('eyecatcher'); 
    $source = Zend_Registry::get('config')->content->imageRelativeLocation . $this->eyecatcher_image['image_url']; 
    $eyecatcher->setValue("<img src='{$source}'/>"); 
    $eyecatcher_form->addElement($eyecatcher); 
    $eyecatcher_form->addElement('button', "deleteEyecatcher{$this->eyecatcher_image['id']}", array('label' => 'delete', 'class' => 'delete', 'itemid' => $this->eyecatcher_image['id'])); 
} 
$eyecatcher_form->setDecorators(array("ViewHelper")); 
$eyecatcher_form->setDecorators(array("FormElements", "Form", array('HtmlTag', array('tag'=>'div' , 'class' => 'eyecatcher_item')))); 

$this->addSubForm($eyecatcher_form, 'eyecatcher'); 

return $eyecatcher_form; 

}

感谢您的帮助,到目前为止,我已经接到了几步进一步为解决这个问题:)

回答

2

子窗体不应该包括自己<form>标签。那就是打破你的提交按钮。你能仔细检查你的子表单是否扩展为Zend_Form_SubForm?如果是这样,请发布您的一种子窗体方法的代码(或相关部分)。

编辑:你还有你的眼睛捕手形式的第二种形式的标签,因为你是手动添加表单装饰给分形式(与<form> .. </form>将其包装)。试着行更改设置的装饰到这一点:

$eyecatcher_form->setDecorators(array("FormElements", array('HtmlTag', array('tag'=>'div' , 'class' => 'eyecatcher_item')))); 
+0

我确实搞砸,还是我现在改成了扩展Zend_Form_SubForm的,它仍然拒绝工作,你就像你说的它确实删除

标签子窗体。 – 2012-08-01 06:49:25

+0

看到我编辑的答案 – 2012-08-01 08:11:52

+0

当然,不能相信我错过了。它现在工作:)非常感谢! – 2012-08-01 10:36:04