[eluser]the_unforgiven[/eluser]
When i clcik the edit link to go to the following url: http://localhost/ci/admin/update/69
it grabs the id and does eaxtly what it's suppose to but when navigating to the above a blank white screen appears nothing else
[eluser]the_unforgiven[/eluser]
I've edited the form to incorporte what you said but still blank screen
Code: echo form_open('admin/update/'.$id); ?>
<table name="editform" cellpadding="1">
<tr>
<td class="table_title">Page Title:</td>
<td><input type="text" name="name" title="name" value="<?php echo set_value('name', $name); ?>" /></td>
</tr>
<tr>
<td class="table_title">Description:</td>
<td><textarea name="description" title="description" cols="50" rows="8"><?php echo set_value('description', $description); ?></textarea></td>
</tr>
<tr>
<td class="table_title">Keywords:</td>
<td><input type="text" name="keywords" title="keywords" value="<?php echo set_value('keywords', $keywords); ?>" /></td>
<td><small>max 5 keywords seperated by a comma ,</small></td>
</tr>
<tr>
<td class="table_title">Content:</td>
<td><textarea name="content" title="Content" cols="50" rows="8"><?php echo set_value('content', $content); ?></textarea></td>
<td><small>max 2000 characters</small></td>
</tr>
<tr>
<td class="table_title"></td>
<td><input type="hidden" name="lang_id" value="1" /></td>
<td><input type="hidden" name="id" value="<?php echo set_value('id', $id); ?>" /></td>
<td><input type="hidden" name="form" value="edit" /></td>
</tr>
<tr>
<td class="table_title"></td>
<td><input type="submit" name="submit" value="Save" /></td>
</tr>
<tr>
<td class="table_title"></td>
<td><a href="admin/pages" title="Back">Back</a></td>
</tr>
</table>
<?php
echo form_close();
[eluser]the_unforgiven[/eluser]
Also i understand the code wasn't meant for me to work “out of the box” but it made sense and by re-using that code will make me understand more than sat here thinking how do you do .... ..... etc
[eluser]LuckyFella73[/eluser]
Quote:When i clcik the edit link to go to the following url: http://localhost/ci/admin/update/69
it grabs the id and does eaxtly what it’s suppose to but when navigating to the above a blank white screen appears nothing else
Don't you get the prefilled form at all or do you get a blank page after submitting?
btw.: if you have this in your controller when calling your model:
Code: if ( $query === FALSE) // .....
You have to return 'true' or 'false' depending if the query worked.
Otherwise your code allways 'thinks' it's 'false'.
Code: //Update page model
function update_page($data)
{
//$id = $this->input->get('id');
$this->db->where('id', $this->input->post('id'));
if ( $this->db->update('ci_pages', $data) )
{
return TRUE;
}
else
{
return FALSE;
}
}
[eluser]the_unforgiven[/eluser]
I just get a blank screen when the link is clicked doesn't even show the edit form
[eluser]the_unforgiven[/eluser]
Just going through the code now i think something is missing like a ; or something for it to be a blank screen once the link is clicked otherwise if it was anything else it show an error or even so they form had been populated, right??
[eluser]the_unforgiven[/eluser]
I'm guessing this IF statement has something to do with it cos when i changed it something completely random it throws back an error
Code: if (isset($_POST['form']) AND $_POST['form'] == 'edit')
[eluser]LuckyFella73[/eluser]
I have this line in a running project and it works so I assume
that can't be the error.
Maybe the error is somewhere else in your controller? Could you
post the whole controller code?
[eluser]the_unforgiven[/eluser]
Yes sure here it is:
Code: <?php
class Admin extends CI_Controller {
function index()
{
// Load Libary & Helper Files
$this->load->database('ci');
$this->load->library(array('encrypt', 'form_validation', 'pagination', 'session'));
$this->load->helper(array('form', 'url'));
$this->load->view('admin/dashboard');
$id = $this->session->userdata('session_id');
}
// Success for edited page
function pagesuccess() {
$data['title'] = 'Page Updated';
$this->load->view('admin/pagesuccess', $data);
}
// Pages Function
function pages() {
$data = array();
if($query = $this->page_model->getAllPages())
{
$data['pages'] = $query;
$data['title'] = 'Page Management';
}
$this->load->view('admin/pages', $data);
}
//Update Function
function update() {
$this->load->helper('form');
$this->load->library('form_validation');
if (!empty($_POST['form']) AND $_POST['form'] == 'edit')
{
# Form was send:
$this->id = $this->input->post('id');
$this->load->helper('form');
$this->load->library('form_validation');
# Rules:
$this->form_validation->set_rules('name', 'Page Title', 'trim|required|min_length[2]|max_length[120]|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'trim|required|min_length[3]|max_length[160]|xss_clean');
$this->form_validation->set_rules('keywords', 'Keywords', 'trim|required|min_length[3]|max_length[160]|xss_clean');
$this->form_validation->set_rules('content', 'Content', 'trim|required|min_length[3]|max_length[2000]|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$data['id'] = $this->input->post('id');
$data['name'] = $this->input->post('name');
$data['description'] = $this->input->post('description');
$data['keywords'] = $this->input->post('keywords');
$data['content'] = $this->input->post('content');
$data['status'] = $this->input->post('status');
$this->load->view('admin/editpage', $data);
}
else
{
$data = array(
'name' => $this->input->post('name'),
'description' => $this->input->post('description'),
'keywords' => $this->input->post('keywords'),
'content' => $this->input->post('content'),
'status' => $this->input->post('status')
);
$query = $this->page_model->update_page($data, $this->id);
if ( $query === FALSE)
{
$data['msg'] .= 'failed'; // echo in view file
}
redirect('admin/editpage', 'refresh');
}
}
else
{
$this->id = $this->uri->segment(3);
$data['id'] = $this->id;
# Get DB data
$query = $this->page_model->getAllPages($this->id);
if ($query === FALSE)
{
echo ("query failed");
exit();
}
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data['id'] = $this->id;
$data['name'] = $row->name;
$data['description'] = $row->description;
$data['keywords'] = $row->keywords;
$data['content'] = $row->content;
$data['status'] = $row->status;
}
}
else
{
echo "This is the last else statement!";
exit();
}
// send db data to the form
$this->load->view('admin/editpage', $data);
}
}
// Delete Page
function delete() {
$this->page_model->delete_page();
$data['title'] = 'Page Deleted';
$this->load->view('admin/deletesuccess', $data);
}
}
?>
[eluser]LuckyFella73[/eluser]
The closing bracket of the class is missing! The last
part of your controller:
Code: # You have this now:
// Delete Page
function delete() {
$this->page_model->delete_page();
$data['title'] = 'Page Deleted';
$this->load->view('admin/deletesuccess', $data);
}
?>
#Has to be this:
// Delete Page
function delete() {
$this->page_model->delete_page();
$data['title'] = 'Page Deleted';
$this->load->view('admin/deletesuccess', $data);
}
} // this one is missing!
?>
|