在另一个表单中收集表单数据的可能方法是什么?

时间:2014-10-15 05:46:02

标签: php forms

我相信我们不能将一个表格嵌入另一个表格中。但我的情况需要某种解决方案。请提供可能的解决方法。

有一个表单可以收集要新上传到数据库的产品的所有信息。现在我需要允许用户在提交表单之前为每个产品添加多个尺寸。

我想过使用session来提交多个大小,但它似乎不是完美的解决方案。

感谢任何帮助。谢谢。

3 个答案:

答案 0 :(得分:0)

首先,这不是有效的HTML或XHTML。无法保证跨浏览器支持。你应该不这样做。 官方规范声明:

"表单不得包含其他表单元素。" http://www.w3.org/TR/xhtml1/#prohibitions(XHTML Specs Section B." Element Prohibitions")

"每个表单都必须包含在FORM元素中。单个文档中可以有多个表单,但FORM元素不能嵌套。" (HTMl 3.2规格)

通过这方面的解决方法。试试这个吧。 http://blog.avirtualhome.com/how-to-create-nested-forms/

答案 1 :(得分:0)

正如Marcus Rommel所提到的那样,只使用一种形式,嵌套表格并不是一种好习惯。
您的问题没有给出太多信息,但据我所知,您希望用户为每种产品输入大量尺寸,具体如何:

<form role="form">
  <div>
    <label for="InputProduct">Product</label>
    <select>
      <option>Product 1</option>
      <option>Product 2</option>
      <option>Product 3</option>
    </select>
  </div>
  <div>
    <label for="InputProductNumber">How Many?</label>
    <input type="number" max="10" placeholder="Small Size">
    <input type="number" max="10" placeholder="Medium Size">
    <input type="number" max="10" placeholder="Large Size">
  </div>
   <button type="submit">Submit</button>
</form>

当然,您可以为每个产品创建更多产品选择,然后为每个尺寸输入一个数字。

答案 2 :(得分:0)

像Hanky웃Panky建议的那样。

 <form>
  here you add your normal fields.
 <dev id='addable'>
  here the default no of elements
 </dev>
 <button onclick='addElement()'>
 </form>

免责声明:如果您没有提供任何代码,这只是大纲。

 <script>
 function addElement() {
 document.getElementById("addable").innerHTML += "here you add the element code you want"; 
 //i.e. "<input name="size[]" type="text"/>"
 }
 </script>

有关如何制作它的更多方法,请搜索&#34; javascript添加更多元素以形成&#34;。