Welcome Guest, Not a member yet? Register   Sign In
Basic 'Update Entry' Script help...
#1

[eluser]invision[/eluser]
Hi,

I'm working on a very basic Guestbook and I'm 90% of the way there.

However, I'd like to be able to allow Guests to edit posts. They can even edit others' posts, for now Smile

View:
Code:
<html>
<head>
<title>Update Entry | Guestbook | CodeIgniter</title>

<style type="text/css">

body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 12px;
color: #4F5155;
}

</style>
</head>
<body>

<h1>Welcome to the Guestbook!</h1>

<p>Edit an entry on my Guestbook.</p>

&lt;?php

echo validation_errors('<div class="error">', '</div>');

echo '<p>&nbsp;</p>';

echo form_open('guestbook/update/');

echo form_label('What is your Name?', 'author');
echo '<br />';
echo form_input('author', '');

echo '<br /><br />';

echo form_label('Your Comments', 'comments');
echo '<br />';
echo form_textarea('comments', '');

echo '<br /><br />';

echo form_submit('mysubmit', 'Update Entry!');

form_close();

?&gt;

<p>&nbsp;</p>

<p><br />Page rendered in {elapsed_time} seconds</p>

&lt;/body&gt;
&lt;/html&gt;

Controller:
Code:
function update()
    {
    $this->load->helper(array('form', 'url'));        
        $this->load->library('form_validation');        
        $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
                    
        /* Form Validation */            
        $this->form_validation->set_rules('author', 'Author', 'trim|required');
        $this->form_validation->set_rules('comments', 'Comments', 'trim|required');  
    
        #Input and textarea field attributes
        $data["author"] = array('name' => 'author', 'id' => 'author');
        $data['comments'] = array('name' => 'comments', 'id' => 'comments');
        
                
        if ($this->form_validation->run() == FALSE)
        {    
          $data['post'] = $this->Guestbook_model->getEntry($id);
          $this->load->vars($data);
          $this->load->view('update');
        }
        else
        {        
        $this->load->model('Guestbook_model');
        $data['cats'] = $this->Guestbook_model->updateEntry();
        $this->load->vars($data);
        $this->load->view('update_success');
        }
    }

Model:
Code:
function updateEntry(){
        $data = array('author' => $this->input->post('author'),
        'content' => $this->input->post('content')
        );
        $this->db->where('id',$this->input->post('id'));
        $this->db->update('data',$data);
    }


I basically want to know how to:

1) pre-fill my input fields with the existing author/comments values for that post
2) update the guestbook entry when submitted correctly.


Many thanks for any help you can give.


Messages In This Thread
Basic 'Update Entry' Script help... - by El Forum - 04-28-2010, 02:13 AM
Basic 'Update Entry' Script help... - by El Forum - 04-28-2010, 02:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB