Welcome Guest, Not a member yet? Register   Sign In
How to pass ID through a form?
#1

[eluser]Volkof[/eluser]
Hi guys,

In my view, I have a review(basically a paragraph of text) and a comment box at the bottom. Since the review is fetched from database, I have the reviewID.
So now what Im trying to do is when a user enters comments into the box and click submit, the reviewID and comments will be passed to the controller to store into the database.
Problem is I'm not sure how to pass the reviewID through <form>

Code:
echo form_open('comment/addComment/');
  //echo validation_errors();
  
  $comment = array(
              'name'        => 'comment',
   'rows'  => '4',
              'cols'        => '30',
            );
  
  echo "<p>Your comment for this review:<br/>";
  echo form_textarea($comment);
  echo "</p>";

  echo "<p>";
  echo form_submit('submit', 'Post Comment');
  echo "</p>";

  echo form_close();

I tried
Code:
echo form_open('comment/addComment/'$row->reviewID);
but it does not work.

Any idea? Thanks in advance
#2

[eluser]maesk[/eluser]
Hi,

I would use a hidden form field for this. Before your "form_close();" add:

Code:
echo form_hidden('reviewID', $row->reviewID);

Then, in your controller, you can access the value with

Code:
$this->input->post('reviewID');

Check out the form helper for more information about creating hidden fields:
http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]Volkof[/eluser]
Thanks Smile




Theme © iAndrew 2016 - Forum software by © MyBB