0

1 つの送信ボタンで送信したいフォームがあります。

ただし、ファイルをアップロードする私のアクションは、データベースの投稿とは異なるコントローラーです。このように見えます...

<form method="post" action="/admin/upholstery_product/add/">
<h3>Add a Product</h3>
Frame: <input type="text" name="productname" /><br>

Parent Category:
<select name="category">
    <?php
    foreach($cats AS $cat){
        $sel = ($curCat->category_id == $cat->category_id) ? 'selected' : '';

        echo "<option value='".$cat->category_id."' ".$sel.">" . $cat->category_name . "</option>\n";
    }
    ?>
</select><br />

Family: <input type="text" name="family" /><br>

Width: <input type="text" name="width" size="6" /><br>

Height: <input type="text" name="height" size="6" /><br>

Depth: <input type="text" name="depth" size="6" /><br>

Seat Width: <input type="text" name="seat_width" size="6" /><br>

Seat Height: <input type="text" name="seat_height" size="6" /><br>

Seat Depth: <input type="text" name="seat_depth" size="6" /><br>

Arm Height: <input type ="text" name="arm_height" size="6" /><br>

Features: <textarea cols="40" rows="20" name="features"></textarea><br>

<form method="post" action="/upload/product_image_upload">
Image File: <input type="file" name="image" id="image"/><br>
</form>

<form method="post" action="/upload/product_image_upload">
Thumbnail File: <input type="file" name="thumbnail" id="thumbnail"/><br>
</form>

<form method="post" action="/upload/pdf_upload">
PDF File: <input type="file" name="pdf" id="pdf"/><br>
</form>

Status: <select name="status">
        <option value="active">Active</option>
        <option value="inactive">Inactive</option>
        </select> <br>


<input type="submit" name="submit" value="Add Product" /><br>
</form>

ファイル アクションを 1 つのコントローラーに投稿し、1 つの送信ボタンで他のコントローラーに送信する方法はありますか? 現在、コードは機能しません。

4

1 に答える 1

0

あなたがしたいことは、厳密に言えば、不可能です。1 つのページに 2 つの別々のフォームがあり、両方を同時に送信したい場合。

ここでの主な問題は次のとおりです。送信されたフォームの結果は新しいページです。異なるアクション = 異なるページ。どちらを表示しますか?

回避策: ファイルとデータの両方を同じスクリプトに送信します。ハンドラーを分離する必要がある場合は、最初のハンドラーが「舞台裏で」2 番目のハンドラーにデータを送信するようにします。

于 2013-02-13T14:16:30.497 に答える