• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying dynamic form data

#1
[eluser]Chris Williams[/eluser]
After going through the tutorials, I wanted to make a form that was table driven. So the input names come from values of a record set.

Without knowing those names, how do I display $_POST data? Is there helper in CodeIgniter for this?

#2
[eluser]ztinger[/eluser]
Can you elaborate??

I'm not sure if i got right the first part of your post.

To display $_POST data you do this in the controller:

Code:
$data['name']= $this->input->post('name');
// this is the same as $data['name'] = $_POST['name'];

//then you pass it to the view:

$this->load->view('your-view-file',$data);

then in your view file:

Code:
Your name is :<?=$name?>


Was that your question?

#3
[eluser]Chris Williams[/eluser]
Right. I wasn't sure if there was a helper built in for this or not. Basically, my database populates the form which changes week to week. So I can't hard code any of it.

I am using this for dynamically made forms. It works, I didn't know if there was a smarter way around this.

Code:
foreach ($_POST as $i => $someVar)
{    
    if ($someVar != 0){
        $query = $this->db->query("SELECT name, id FROM mytable WHERE id = $i");
        foreach ($query->result() as $row)
        {
           $body .= $row->name . " x " . $someVar . "<br />";
        }
    }    
}
$data['body'] = $body;


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.