Welcome Guest, Not a member yet? Register   Sign In
Passing a URI segment when submitting a form
#1

[eluser]Unknown[/eluser]
Hello,

This is my first venture into these forums, so please be gentle.

I'm just getting to grips with CodeIgniter, and I have a question about setting a URI segment from a form, if that's at all possible.

My controller contains the following snippet at the start:

Code:
$product_id = $this->uri->segment(3, 0);

This Product ID is used in the query to get the data which is used to populate the form in the view. At the end of the function in the controller I have:

Code:
// Run the validation.
if ($this->form_validation->run() == FALSE)
{
    $data['error_msg'] = 'Some kind of error!';
    $this->load->view('product_detail_view', $data);
}
else
{
    $data['error_msg'] = 'No Errors!';
    $this->load->view('product_detail_view', $data);
}


When I call the product detail controller initially, I pass the Product ID as follows:

Code:
anchor('/main/product_detail/'.$row->prod_id,'Details');

Now the problem I have is in the detail view, when the details have been amended I submit them using a basic form. However, this doesn't pass the Product ID as a segment, and I've not been able to find an example of how to do that anywhere.

I'm setting my form up with a simple:

Code:
echo form_open('main/product_detail/');

And submitting it with:

Code:
<input type="submit" value="Submit" />

Chances are I'm going about this the wrong way, so I could use a pointer to set me on the right track please.

Thanks for your time.
#2

[eluser]osci[/eluser]
In controller
Code:
$data['product_id']= $product_id;

and in view
Code:
echo form_open('main/product_detail/'.$product_id);
#3

[eluser]Unknown[/eluser]
That's perfect, thank you.




Theme © iAndrew 2016 - Forum software by © MyBB