douba4824 2013-02-12 06:47
浏览 58

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

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>
";
    }
    ?>
</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.

  • 写回答

1条回答 默认 最新

  • douyong1285 2013-02-13 14:16
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件