Posting multi dimensional form via jquery to php -


i have form. first 2 inputs customer id , address id. rest multidimensional form usuer can dynamically add more items.

<div class='invoice_object'>     <input      name='item[1][quantity]'    type='text'  value=''/>     <textarea   name='item[1][description]'     ></textarea>     <input      name='item[1][unit_price]'  type='text'  value=''/>     <input      name='item[1][amount]'      type='text'  value=''/> </div> 

another invoice object can added jquery , so:

    <div class='invoice_object'>     <input      name='item[2][quantity]'    type='text'  value=''/>     <textarea   name='item[2][description]'     ></textarea>     <input      name='item[2][unit_price]'  type='text'  value=''/>     <input      name='item[2][amount]'      type='text'  value=''/> </div> 

if post submit button $_post variable contain:

$_post['customer'] $_post['address'] $_post['item'] {                 ['1'] {                        ['quantity']                        ['description']                        ['unit_price']                        ['amount']                        }                 ['2'] {                        ['quantity']                        ['description']                        ['unit_price']                        ['amount']                        }                 } 

i've searched hours , tried sorts of versions or serialize , serializearray.json decode etc seems can send string php jquery. using json can php file $_post ends having 1 value , string of data.

i figured there must way of doing it... without manually making function dissects string acording square brackets are.

i advice please. thanx. without panually dissecting

jquery

    var x = $('#new_invoice').serialize();      $.post("script/new_invoice_script.php", {                     x                                            }, function(data) {                          console.log (data);                     }); 

you shouldn't put x inside object. it's in format necessary data argument $.post.

var x = $('#new_invoice').serialize(); $.post("script/new_invoice_script.php", x, function(data) {   console.log(data); }); 

when write { x } it's es6 shorthand { x: x }. puts serialized input string $_post['x'].


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -