CodeIgniter Forums
How to pass data from a view to a controller? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to pass data from a view to a controller? (/thread-27497.html)

Pages: 1 2


How to pass data from a view to a controller? - El Forum - 02-15-2010

[eluser]laytone[/eluser]
try this

Quote:My controller has the following code:
$project_id = $this->input->post(“ProjectID”);
echo $project_id;

Code:
echo "<pre>";
print_r($_POST);
echo "</pre>";

This way you can see all the variables that your form is posting. Maybe in your html the hidden fields are not within your &lt;form&gt;&lt;/form> tags?.?.?


How to pass data from a view to a controller? - El Forum - 02-15-2010

[eluser]theciman[/eluser]
Thanks but I tried that with no results. I do believe I have all the form tags correct:

&lt;form&gt;
&lt;/form&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt; TRMC T&E S&T &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>Database Update</h1>
Project Details:<br />
<pre>
&lt;form action="http://abc.ef.com/ll/index.php/updateprojects/update_project" method="post"&gt;
......
......
&lt;/form&gt;
</pre>
&lt;/body&gt;
&lt;/html&gt;

The funny thing is when I make the form viewable it works fine.


How to pass data from a view to a controller? - El Forum - 02-15-2010

[eluser]laytone[/eluser]
Can you post the rendered html view and also the function you are posting to without removing any of the actual code?

Quote:The funny thing is when I make the form viewable it works fine.

what do you mean by this and how is it that you are hiding it?


How to pass data from a view to a controller? - El Forum - 02-15-2010

[eluser]theciman[/eluser]
What I meant is I am using a form_hidden which gives me this problem. Once I change the form_hidden to say form_input then everything works fine. This is why I think there is something wrong with the form_hidden function. I am questioning whether one can pass a value to a controller using $this->input->post coming from a form_hidden function. I am told I should be able to pass a value but it does not seem to work. The value is correct in the html code I show above but yet the post shows nothing. Once I make the form visible like a form_input than the value is captured by the post method and I can view it, modify it, and use it to insert values into my database.


How to pass data from a view to a controller? - El Forum - 02-15-2010

[eluser]laytone[/eluser]
I do it every day. Will you post the html code of your form rendered. from the <from XXX > to the &lt;/form&gt; without taking anything out. (the version with hidden fields) I'm sure we will be able to figure out whats wrong very quickly.