1

特定のビューのデフォルト フォームがあります。

要素を介して、アップロードフォームを提供するために、(ビュー拡張を使用して) 別のビューを (動的に) インクルードします。

私の問題は、2 番目のフォームが最初のフォームを送信しているように見えることです。

デフォルトフォーム

<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 を提供して最後のフォームを強制しようとしましたが、送信すると、最初のフォームと同じようにデータが送信されます。

これをどのように処理すればよいですか?

ありがとうございました!

4

1 に答える 1

3

親からのフォームと子ビュー/要素からのフォームの両方が必要な場合は、両方のテンプレートで $this->Form->end() を呼び出し、他のフォーム内にフォームをネストしていないことを確認してください. おそらく、あなたの場合、 end() を両方のフォームに追加するだけで問題が解決します。

補足として、親ビューで $this->Form->create() を使用してフォームを開き、子ビューを使用してフィールドを挿入することはできません。基本的に、入力がレンダリングされる前に create() を呼び出す必要があるためです。親ビューは、子が実行された後にレンダリングされます。

于 2012-08-02T17:50:20.093 に答える