2017-08-29 53 views
-1

我有一個表單。PHP表格組織數組中的數據

整個div.wrap-all都可以使用表單中的jquery進行復制。

此外,input.foo可以div.wrap字幕

我怎麼能得到陣列分離形式裏面的數據被複制所以每div.wrap,所有在分開陣列中的數據?

下面是一個例子(很簡單):

<form> 
    <div class="wrap-all"> 
     <input type="text" name="question[]"> 
     <div class="wrap-subtitle"> 
      <input class="foo" type="text" name="subtitle[]"> 
     </div> 
    </div> 
    <input type=submit> 
</form> 

下面是一個例子如何可能看起來像之前提交:

<form> 
    <div class="wrap-all"> 
     <input type="text" name="question[]"> 
     <div class="wrap-subtitle"> 
      <input class="foo" type="text" name="subtitle[]"> 
      <input class="foo" type="text" name="subtitle[]"> 
      <input class="foo" type="text" name="subtitle[]"> 
     </div> 
    </div> 
    <div class="wrap-all"> 
     <input type="text" name="question[]"> 
     <div class="wrap-subtitle"> 
      <input class="foo" type="text" name="subtitle[]"> 
      <input class="foo" type="text" name="subtitle[]"> 
     </div> 
    </div> 
    <input type=submit> 
</form> 
+0

''如果這是一個錯字,您需要更新您的文章。它應該讀作'

'。有些人甚至可能會發布答案。 –

回答

0

我知道在HTML多維數組的方式。這是一個示例。

<form action="" method=post> 
    <input type="text" name="field[step1][]"> 
    <input class="foo" type="text" name="field[step2][]"> 
    <input type=submit> 
</form> 

結果print_r($_POST);以PHP結果。

Array 
(
    [field] => Array 
     (
      [step1] => Array 
       (
        [0] => 1 
       ) 

      [step2] => Array 
       (
        [0] => 2 
       ) 
     ) 
) 
+0

仍然不會回答如何獲得在數組中分隔的表單數據,所以每個div.wrap-all都有獨立數組中的數據? – Toniq

+0

如果你要求jQuery,你不能用jQuery函數來做到這一點。這裏有一個關於https://codepen.io/alexweissman/pen/MyWZdN的想法 –