CodeIgniter Forums
Displaying dynamic form data - 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: Displaying dynamic form data (/thread-1958.html)



Displaying dynamic form data - El Forum - 07-07-2007

[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?


Displaying dynamic form data - El Forum - 07-07-2007

[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?


Displaying dynamic form data - El Forum - 07-08-2007

[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;