2012-08-02 47 views
1

我有我的特定视图的默认窗体。如何在同一视图中处理多个表单?

通过一个元素I(dinamically)包含另一个视图(使用视图扩展)以提供一个上传表单。

我的问题是,第二种形式似乎提交第一个。

缺省形式

<div class="content-box-content"> 
     <?php 
      echo $this->Form->create("WebSubject", array(
       'inputDefaults' => array(
        'error' => array(
         'attributes' => array(
          'wrap' => 'span', 
          'class' => 'input-notification error png_bg' 
         )     
        ) 
       ) 
      )); 
     ?> 

     <?=$this->Form->input('id', array('type' => 'hidden'))?> 

     <?=$this->Form->input('title', array('class' => "text-input small-input", 'label' => 'Denumire'))?> 

     <?=$this->Form->input('description', array('type' => 'textarea', 'label' => 'Descriere', 'id' => 'description'))?> 

     <?=$this->Form->input('description_long', array('type' => 'textarea', 'label' => 'Continut', 'id' => 'description_long'))?> 

     <?=$this->Form->submit('Salveaza', array('class' => "button"))?> 
    </div> 

这样我包括元素

<div class="tab-content default-tab" id="fotoUploadTab"> 
      <?php 
       echo $this->element('file_upload_form', array(
         'view' => 'upload_admin', 
         'webFileType' => 'image', 
         'redirect' => $SHT['here'] 
        ) 
       ); 
      ?> 
      <div class="tab-content default-tab"> 
       Lista imagini 
      </div> 
     </div> 

元代码

<?php 
    $view = (isset($view)) ? $view : "upload_admin"; 
    $webFileType = (isset($webFileType)) ? $webFileType : "image"; 
    $redirect = (isset($redirect)) ? $redirect : "/"; 
?> 
<?php 
    $this->extend("/WebFiles/".$view); 
?> 

扩展视图代码

<div class="tab-content default-tab"> 

    <?php echo $this->Form->create("WebFile", array('action' => '/', 'type' => 'file')); ?> 

    <input type="hidden" name="redirect" value="" /> 
    <?php echo $this->Form->input('entity_id', array('type' => 'hidden')); ?> 
    <?php echo $this->Form->input('entity_table_name', array('type' => 'hidden')); ?> 
    <?php echo $this->Form->input('type', array('type' => 'hidden')); ?> 

    <?php echo $this->Form->input('title', array('class' => "text-input small-input", 'label' => 'Denumire')); ?> 
    <?php echo $this->Form->input('description', array('class' => "text-input small-input", 'label' => 'Descriere')); ?> 
    <?php echo $this->Form->submit('Upload', array('class' => 'button')); ?> 

</div> 

正如上段看到,我试图通过提供一个动作URL,迫使最后一种形式,但它submiting,将其作为第一个做数据。

我该如何处理?

谢谢!

回答

3

如果你只是想要两个表单,一个来自父视图,另一个来自子视图/元素,确保你在两个模板中调用$ this-> Form-> end(),并且你不是嵌套在另一个里面形成。也许,就你而言,只需在两个表单中添加end()就可以解决你的问题。作为一个方面说明,你不能有一个父视图用$ this-> Form-> create()打开一个Form,并使用子视图向它注入字段,这基本上是因为你需要在之前调用create()任何输入都会被渲染,并且父视图在孩子执行后被渲染。

+0

Got it!谢谢你,何塞! – Michael 2012-08-02 18:36:14

相关问题