简体   繁体   English

表单和文件上传到两个不同的控制器

[英]form and file upload to two different controllers

I have a form that I want to submit with one submit button. 我有一个要通过一个提交按钮提交的表单。

However my action to upload a file is a different controller then the database posts. 但是,我上传文件的操作是与数据库发布不同的控制器。 it looks like this... 看起来像这样...

<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>

is there a way to post the file actions to one controller and the submit to my other controller with a single submit button? 有没有一种方法可以将文件操作发布到一个控制器,然后通过一个提交按钮将其提交到我的另一个控制器? right now the code doesnt work. 现在代码不起作用。

What you want to do is, strictly speaking, not possible: You have two separate forms on one page, andf you want to submit both simultanously. 严格来讲,您想做的是不可能的:您在一页上有两个单独的表单,并且要同时提交两个表单。

The main problem here is this: The result of a submitted form is a new page. 这里的主要问题是:提交表单的结果是一个新页面。 Different actions = different pages. 不同的动作=不同的页面。 Which one do you want to display? 您要显示哪一个?

Workaround: Submit both the file and the data to the same script; 解决方法:将文件和数据都提交到同一脚本; if the handlers need to be separate, make the first handler post the data to the second handler "behind the scenes". 如果处理程序需要分开,则使第一个处理程序将数据“在幕后”发布到第二个处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM