I am certain I am making a simple mistake... but simply can't find it.
Ultimately I am posting a JSON array from an Android app (that part is working), but for the time being I am simply testing between two PHP pages (1: test PHP page with basic form, and 2: the CodeIgniter final destination) Here is what I have:
At the form page:
<form action="bambooinvoice/index.php/api2/newinvoice/4/0/0" method="post">
<?php
$array = array("items"=>array(
"taxable"=>1,
"quantity"=>1,
"amount"=>123.99,
"work_description"=>"this is a test"));
$json = json_encode($array);
?>
<input type="hidden" name=json value=<?php $json ?> />
<input type="submit" name="btnSendForm" value="Send" />
</form>
This creates (which looks good to me):
{"items":{"taxable":1,"Quantity":1,"amount":123.99,"work_description":"this is a test"}}
On the codeIgniter side, I have:
$input = $this->input->post('json');
$items = json_decode($input, TRUE);
$amount = 0;
foreach ($items as $item) // In case there are multiple 'items'
{
$taxable = (isset($item['taxable']) && $item['taxable'] == 1) ? 1 : 0;
$invoice_items = array(
'quantity' => $item['quantity'],
'amount' => $item['amount'],
'work_description' => $item['work_description'],
'taxable' => $taxable
);
$this->_addInvoiceItem($invoice_items); //simply adding contents to DB
}
In the end I receive the error: (i have received numerous errors actually in all my tweaking, but this is the one I can't seem to shake)
Message: Invalid argument supplied for foreach()
Edited - to correct a typo.
var_dump()ing$itemsand$jsonto ensure they are what you expect them to be?JSONdata to an attribute. I'm assuming this is causing some brokenness in theDOM, and the POST data is also broken.<?=$json?>or<?php echo $json?>