Welcome Guest, Not a member yet? Register   Sign In
How to access values returned from view form
#1

[eluser]TWP Marketing[/eluser]
I'm stuck on a point using the cart library.
The userguide (SVN) page gives an example of how to pass the 'rowid' and 'qty' values from the view form to the controller/model.

Code:
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<?php echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5'));

This is accessed using $this->input->post () and I can see the posted values using profiler, for example

Code:
_POST[1] array( [rowid] => 7c9d5fbcdc5ae18a05e0b792cfccafbf, [qty] => 1);
_POST[2] array( [rowid] => 8ddf6ceb54ab84a0e9eab4765f4cabcd, [qty] => 1);

Noting the array keys "[rowid]" and "[qty]" do _NOT_ fit the proper expression for array indexes (I think),
How do I reference these posted values?

I've tried the following, which fail to return anything, (empty string), or produce a php warning of incorrect usage of index:
Code:
$rowid = $this->input->post ($i.'[rowid]');
$qty = $this->input->post ($i.'[qty]');

Thanks
Dave
#2

[eluser]Colin Williams[/eluser]
You have to understand your array. Each value in post is an array. There is a $_POST[0]['rowid'] but there is no $_POST[0[rowid]] and that is why your methodology is failing. It would be more appropriate to do:

Code:
$rowid = $this->input->post("[$i][rowid]");
#3

[eluser]TWP Marketing[/eluser]
Thanks for the reply,
I solved the problem using
Code:
$item = $this->input->post($i);
which returns the whole array as $item and I can access the elements normally via
Code:
$rowid = $item['rowid'];
$qty = $item['qty'];
I enclose this in a loop and process all of the items from the order.

I missed fact that the form was returning an array (not enough/too much coffee?).
Dave




Theme © iAndrew 2016 - Forum software by © MyBB