Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax multidimensional form data in same format as $_POST
    primarykey
    data
    text
    <p>I have a form with deep multidimensional inputs like so:</p> <pre><code>&lt;form id="theForm"&gt; &lt;input type='text' name='one[two][three][]' /&gt; &lt;input type='text' name='one[two][three][]' /&gt; &lt;input type='text' name='four[five][six][seven]' /&gt; &lt;input type='text' name='eight[nine][ten]' /&gt; &lt;/form&gt; </code></pre> <p>I am trying to send the values via AJAX in the same format as if the form was submitted normally. What I mean is, if I were to hit the submit button, in PHP, $_POST would look like this. This is what I want:</p> <pre><code>array( 'one' =&gt; array( 'two' =&gt; array('three'=&gt;array( [0] =&gt; "", [1] =&gt; "" ) ) ), 'four' =&gt; array( 'five' =&gt; array ('six' =&gt; array( 'seven' =&gt; "" ) ) ), 'eight' =&gt; array( 'nine' =&gt; array( 'ten' =&gt; "" ) ) ) ) </code></pre> <p>I am essentially trying to AJAX the form submission. When I do</p> <pre><code>$("#theForm").serializeArray() </code></pre> <p>And the send that over <code>$.post()</code> my $_POST looks like this:</p> <pre><code>array( [0] =&gt; array( "name" =&gt; string "one[two][three][]", value=&gt;"") [1] =&gt; array( "name" =&gt; string "one[two][three][]", value=&gt;"") [2] =&gt; array( "name" =&gt; string "four[five][six][seven]", value=&gt;"") [3] =&gt; array( "name" =&gt; string "eight[nine][ten]", value=&gt;"") ) </code></pre> <p>This is of no use to me. I need to preserve the multidimensional structure I outlined before. I suppose I could walk through the array and chop up the string to recreate what I need, but this seems asinine to me. Is the a jQuery friendly way to accomplish this?</p> <p>I've read the other posts about how jQuery can send multidimensional arrays just fine, so maybe the question I need to ask is, how do I extract my form data, keeping it in a multidimensional array? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload