Welcome Guest, Not a member yet? Register   Sign In
How to get ID related to form input ??
#1

[eluser]umbongo[/eluser]
Code:
foreach($items as $item):

echo $item->id;

echo form_hidden('id',$item->id);
echo form_input(array(~blahblahblah~));

echo form_submit('do','add');
echo form_close();

endforeach;

Here $this->input->post('id') returns the last item printed on the page. How can I get it to refer to the relevant input box??
#2

[eluser]K-Fella[/eluser]
When you say "relevant input box" what do you mean?

If you're going to have lots of hidden fields they should each have their own unique name/id.

Code:
foreach($items as $item):

echo $item->id;

echo form_hidden('id' . $item->id, $item->id); // changed to make id unique
echo form_input(array(~blahblahblah~));

echo form_submit('do','add');
echo form_close();

endforeach;
#3

[eluser]umbongo[/eluser]
There is an input field relating to each item.

RE: your code; I thought of doing this, but then how do i call the item id from outside that file (ie. a controller)?? (what was $this->input->post(‘id’))
#4

[eluser]Bart Mebane[/eluser]
I think this may be what you're trying to do:

In the view ...
Code:
echo form_open();

foreach($items as $item)
{
    echo form_input('last_name[' . $item->id . ']', $item->last_name);
}

echo form_submit('do','add');
echo form_close();
In the controller ...
Code:
if ($this->input->post('do'))
{
    $last_name_array = $this->input->post('last_name');
    foreach ($last_name_array as $id=>$value)
    {
         $this->model->update_last_name($id, $value);
    }
}

Obviously this leaves out a lot of details, but the basic idea is to use an array for the name of the text fields, and use the id as the array index. If you want to have a separate submit button for each id, you can also use an array for the button name.




Theme © iAndrew 2016 - Forum software by © MyBB