Welcome Guest, Not a member yet? Register   Sign In
Form validation always returning false with no errors!
#1

[eluser]Unknown[/eluser]
I have literally been staring at this for 5 hours. It's probably something really simple. Please help before the find me hanging from the rafters (joke)

The Controller
Code:
<?php
class Admin extends CI_Controller
{

function __construct()
{

  parent::__construct();
  $this->load->library('ion_auth');
  $this->load->model('admin_model');
  $this->load->helper('form');
  $this->load->library('form_validation');

}

function index()
{

  if(!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
  {
  
   $this->session->set_flashdata('message','You need to be logged in to access this area of the site');
   redirect('auth/login','refresh');
  
  } else {
  
   $this->load->view('admin/admin_home_view');
  
  }

}

function manage_home_page_content()
{
  
  if($this->ion_auth->logged_in() && $this->ion_auth->is_admin())
  {

  
   if($this->form_validation->run() == FALSE)
   {
    
    
    
    $this->form_validation->set_rules('content_body', 'Content Body', 'required');
    $this->form_validation->set_rules('content_id', 'Content ID', 'required|numeric');

    $content = $this->admin_model->get_home_page_content();
    
    $data['message'] = $this->session->flashdata('message');
    $data['error'] = $this->session->flashdata('error');
    $data['content_id'] = $content['content_id'];
    $data['content_body'] = $content['content_text'];
    
    $this->load->view('admin/manage_home_page_content_view',$data);

   } else {

    
    $content_id = $this->input->post('content_id');
    $data['content_body'] = $this->input->post('content_body');
    $data['content_updated_by'] = $this->ion_auth->user['user_id'];
    $data['content_updated_time'] = time();
    
    
    if($this->admin_model->edit_home_page_content($content_id,$data) == TRUE)
    {
    
     $this->session->set_flashdata('message','Changes Saved Succesfully');
     redirect('admin/manage_home_page_content');
    
    
    } else {
    
     $this->session->set_flashdata('error','Error updating content. Please try again');
     redirect('admin/manage_home_page_content');
    
    }
    

   }
  
  } else {
  
   $this->session->set_flashdata('message','You need to be logged in to complete this action');
   redirect('auth/login','refresh');
  
  }
  
}
    
}

The Model
Code:
<?php
class Admin_model extends CI_Model
{

function __construct()
{

  parent::__construct();
  $this->load->database();
  
}

function get_home_page_content()
{

  $this->db->select('content_id, content_body');
  $this->db->where('content_page','home');
  $query = $this->db->get('content');
  $results = $query->result();
  
  $content['content_id'] = $results[0]->content_id;
  $content['content_text'] = $results[0]->content_body;
  
  return $content;
  
}

function edit_home_page_content($content_id,$data)
{
  
  $logged_in_user = $this->ion_auth->user()->row();
  $content_edited_by = $logged_in_user['user_id'];
  
  $data['content_updated_time'] = time();
  $data['content_updated_by'] = $content_edited_by;
  
  return $this->db
   ->where('content_id',$content_id)
   ->update('content',$data);

}

}

and the view

Code:
<?php
$this->load->view('header_view');
?>

<div id="content-full">

  &lt;?php $this->load->view('admin/admin_menu_view'); ?&gt;

  <div id="content-full-right">
  
   <h3>Edit Home Page Content</h3>
  
    <div class="errors">&lt;?php echo validation_errors(); ?&gt;</div>
    
    <p>&lt;?php echo $error; ?&gt;</p>
    <p>&lt;?php echo $message; ?&gt;</p>
  
    &lt;?php
    $attributes = array('class' => 'admin-area-form');    
    echo form_open('admin/manage_home_page_content',$attributes);
    ?&gt;
    
    &lt;input type="hidden" name="content_id" value="&lt;?php echo $content_id; ?&gt;" /&gt;

    
    &lt;textarea name="content-body" id="content-body"&gt;&lt;?php echo $content_body; ?&gt;&lt;/textarea&gt;
    
    [removed]
        
        //&lt;![CDATA[
        CKEDITOR.replace('content-body', {
        
         toolbar: 'MyToolbar',
         height: 500,
      filebrowserBrowseUrl : '/pdw_file_browser/index.php?editor=ckeditor',
      filebrowserImageBrowseUrl : '/pdw_file_browser/index.php?editor=ckeditor&filter=image',
      
           });  
        //]]>
    
    [removed]
    
    <br />
    <br />
    
    &lt;input type="submit" name="save_changes" value=" Save Changes " /&gt;
  
   &lt;/form&gt;
    
  </div>

</div>



&lt;?php
$this->load->view('footer_view');
?&gt;

Please. Someone save my sanity.
Thanks
#2

[eluser]Aken[/eluser]
Place your set_rules() outside of the run() method check.
#3

[eluser]Unknown[/eluser]
5 Hours man!!!!

I could kiss you!!!!!!!

Thanks so much.

#4

[eluser]Aken[/eluser]
Smile




Theme © iAndrew 2016 - Forum software by © MyBB