编辑表单使用codeigniter添加表单验证

Hi i have this edit page, and in edit page when user tried to edit the page i redirected it to the edit page itself then added a flash message that says successfully edited. My problem is i already have the validation on it, lets say that ahm the user tried to input a wrong email address it will validates to invalid email.What happened is that it will validates that invalid email address, now the textfield in the email, the data is still the same how can i properly set into this? can someone help me? is muchly appreciated. Here's my controller below

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Profile extends CI_Controller {
  public function __construct(){
    parent::__construct();   
    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->model('record_model', 'rm');
    if(!$this->session->userdata('loggedIn')){
      redirect('login');
    }
  }

  public function edit_successfully(){
    $this->form_validation->set_rules('firstname', 'First Name', 'required');
    $this->form_validation->set_rules('lastname', 'Last Name', 'required');
    $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
    if($this->form_validation->run() == FALSE){
      $this->data['title'] = 'Edit Profile';
      $sessionData = $this->session->userdata('loggedIn');
      $this->data['id'] = $sessionData['id'];
      $this->data['query'] = $this->rm->getData($this->data['id']);
      $this->session->set_flashdata('error', 1);

      $this->load->view('templates/header', $this->data);
      $this->load->view('pages/edit');
      $this->load->view('templates/footer');
    }else{
      $sessionData = $this->session->userdata('loggedIn');
      $this->data['id'] = $sessionData['id'];
      $update = array(
                'first_name'=>$this->input->post('firstname'),
                'last_name'=>$this->input->post('lastname'),
                'email'=>$this->input->post('email')
                );
      $this->db->where('id', $this->input->post('editData'))->update('register', $update);
      $this->session->set_flashdata('success', 1);
      redirect(base_url().'profile/edit/id/'.$this->data['id']);
    }
  }

  public function edit($id){
    $this->data['title'] = 'Edit Profile';

    $sessionData = $this->session->userdata('loggedIn');
    $this->data['id'] = $sessionData['id'];
    $ID = $this->uri->segment(4);
    $this->data['query'] = $this->rm->getData($ID);

    $this->load->view('templates/header', $this->data);
    $this->load->view('pages/edit', $this->data);
    $this->load->view('templates/footer');

  }

  public function id($id){
    $this->data['title'] = 'View Profile';
    $this->data['viewProfile'] = 'view';

    $sessionData = $this->session->userdata('loggedIn');
    $this->data['id'] = $sessionData['id'];
    $this->data['query'] = $this->rm->getData($id);

    $this->load->view('templates/header',$this->data);
    $this->load->view('pages/profile', $this->data);
    $this->load->view('templates/footer');

  }

    public function index(){
    $this->data['title'] = 'Profile';

    $this->load->view('templates/header', $this->data);
    $this->load->view('pages/profile', $this->data);
    $this->load->view('templates/footer');   
  }

}

Here's my views

<div class="container">
  <div class="welcome_content"> 
    <?php echo $this->load->view('menu/menu'); ?>
    <div class="clearfix"></div>
    <?php if($this->session->flashdata('success')): ?>
      <div class="alert alert-success">
        <a href="#" class="close" data-dismiss="alert">&times;</a>
        <strong>Success!</strong> Successfully Edited.
      </div>
    <?php endif; ?>
    <div class="profile_content">
      <?php if($this->session->flashdata('error')): ?>
        <form action="<?php echo base_url().'profile/edit_successfully'?>" method="post">
          <div class="error">
            <?php echo validation_errors('<div class="error">','</div>');?>
          </div>
          FirstName:<input type="text" name="firstname" value="<?php echo $query->first_name;?>" /><br /><br />
          LastName:<input type="text" name="lastname" value="<?php echo $query->last_name; ?>" />
          <br />
          <br />
          Email:<input type="text" name="email" value="<?php echo $query->email; ?>" />
          <br />
          <br />
          <input type="hidden" name="editData" value="<?php echo $query->id; ?>" />
          <input type="submit" value="Edit" class="btn btn-primary"/>
        </form>
      <?php else: ?>
        <form action="<?php echo base_url().'profile/edit_successfully'?>" method="post">
          <div class="error">
            <?php echo validation_errors('<div class="error">','</div>');?>
          </div>
          FirstName:<input type="text" name="firstname" value="<?php echo $query->first_name;?>" /><br /><br />
          LastName:<input type="text" name="lastname" value="<?php echo $query->last_name; ?>" />
          <br />
          <br />
          Email:<input type="text" name="email" value="<?php echo $query->email; ?>" />
          <br />
          <br />
          <input type="hidden" name="editData" value="<?php echo $query->id; ?>" />
          <input type="submit" value="Edit" class="btn btn-primary"/>
        </form>
      <?php endif; ?>
      <a href="<?php echo base_url().'homepage'?>" title="Back">Back</a>
    </div>
  </div>
</div>

Now in my views in the form action ive added the flashdata error. That executes when the user tried to change the email address or the firstname or lastname. Can someone help me figured this out?