Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can change and not use json_encode and use serialize in you array.</p> <p>Like this in your form:</p> <pre><code>&lt;form action="bambooinvoice/index.php/api2/newinvoice/4/0/0" method="post"&gt; &lt;?php $array = array("items"=&gt;array( "taxable"=&gt;1, "quantity"=&gt;1, "amount"=&gt;123.99, "work_description"=&gt;"this is a test")); $json = serialize($array); ?&gt; &lt;input type="hidden" name=json value="&lt;?php echo $json ?&gt;" /&gt; &lt;input type="submit" name="btnSendForm" value="Send" /&gt; &lt;/form&gt; </code></pre> <p>This serialize function will create this output:</p> <pre><code>a:1:{s:5:"items";a:4:{s:7:"taxable";i:1;s:8:"quantity";i:1;s:6:"amount";d:123.9899999999999948840923025272786617279052734375;s:16:"work_description";s:14:"this is a test";}} </code></pre> <p>Then in the codeigniter side you can do this:</p> <pre><code>&lt;?php $input = $this-&gt;input-&gt;post('json'); $items = unserialize($input); $amount = 0; foreach ($items as $item) // In case there are multiple 'items' { $taxable = (isset($item['taxable']) &amp;&amp; $item['taxable'] == 1) ? 1 : 0; $invoice_items = array( 'quantity' =&gt; $item['quantity'], 'amount' =&gt; $item['amount'], 'work_description' =&gt; $item['work_description'], 'taxable' =&gt; $taxable ); $this-&gt;_addInvoiceItem($invoice_items); //simply adding contents to DB } ?&gt; </code></pre> <p>but be careful, because when you use a foreach with an array who contain more the 1 level. I hope that this help you.</p>
 

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