Welcome Guest, Not a member yet? Register   Sign In
Input form filled with data
#1

[eluser]Zimooon[/eluser]
Hey guys,

I got an edit function . When i call it i can edit user/posts/etc.. i got some inputs .
Now the problem : when i open f.e. user $id 3 and edit him. I have the fields to set NEW data but i can't see the old / current data of the user. I posted it below but i want to have it into the fields , like a value .
This is one of my views:
Code:
<?php echo form_open('crud/update/'.$id); ?>


    <p> Titel
        &lt;?php echo form_input('title'); ?&gt;
    </p>

    <p> Datum
        &lt;?php echo form_input('date'); ?&gt;
    </p>  
    <p> Aktiv?
        &lt;?php echo form_checkbox('active','1'); ?&gt;  &lt;?php ('active'==1) ?print('checked="checked"'):''; ?&gt;
    <p>
        &lt;?php echo form_textarea('content'); ?&gt;
    </p>

    <p>
        &lt;?php echo form_submit('submit', 'Editieren'); ?&gt;
    </p>

Any ideas?

best regards
#2

[eluser]Zimooon[/eluser]
oh forgot my controller:

Code:
function update()
  {
    
    
    // Check if form is submitted
    if (!$this->ion_auth->logged_in())
    {
            //redirect them to the login page
            redirect('auth/login', 'refresh');
        }

        else
        {
    $id = $this->uri->segment(3);

    if ($this->input->post('submit'))
    {
        
        $title = $this->security->xss_clean($this->input->post('title'));
        $content = $this->security->xss_clean($this->input->post('content'));
        $date = $this->security->xss_clean($this->input->post('date'));
        $active = $this->security->xss_clean($this->input->post('active'));  
        $content = nl2br_except_pre($content);
        
        

        $this->posts_model->updatePost( $id,$title, $content,$date,$active);    
        $data['posts'] = $this->posts_model->getPosts();
        $this->load->view('updateform', $data);                              
        $this->data['title'] = "News";              
    }
    else
     {  
        $data = array('id' => $id);
        $this->load->view('updateform', $data);
     }
  }
#3

[eluser]Zimooon[/eluser]
How to get the title content etc by the $id ? Sad
#4

[eluser]Unknown[/eluser]
I don't know if it matters, but it looks like you are setting your title After you are loading your view.
Does that still work? Or does it skip it?

$this->load->view('updateform', $data);
$this->data['title'] = "News";
#5

[eluser]soupli[/eluser]
1) Put everything you want to pass to your view, before you load the view.

2) And to load current values in input fields, you can use the set_value() method.
Read the user guide on Form Helper.
#6

[eluser]Nisha S.[/eluser]
Set the old values in to some hidden field on the form, so that you can compare when it is posted, or get the old value from the database again.
#7

[eluser]osci[/eluser]
[quote author="Nisha S." date="1307210962"]Set the old values in to some hidden field on the form, so that you can compare when it is posted, or get the old value from the database again.[/quote]
??

use set_value
#8

[eluser]InsiteFX[/eluser]
Download this Auth Library and look at the library class Auth register function, it will show you how to do it all.
Also look at the register view file.
Auth 1.0.6 - by Adam Griffiths

It is for CI 1.7.2 but I have converted it to CI 2.0.+

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB