title: How to repopulate the form data after form validation error in opencart?
body: <p><strong>I have the following code</strong></p>
  
  <pre><code>public function insert()
  {
     $template="information/news_form.tpl"; //Loading the template file for the insert page
    $this-&gt;template = ''.$template.'';
  
   $this-&gt;language-&gt;load('information/news'); // Calling language file
   $this-&gt;load-&gt;model('information/news'); // Calling model file
   $this-&gt;document-&gt;setTitle($this-&gt;language-&gt;get('heading_title'));
  
    $this-&gt;data['breadcrumbs'] = array(); // Home link
    $this-&gt;data['breadcrumbs'][] = array(
       'text' =&gt; $this-&gt;language-&gt;get('text_home'),
       'href' =&gt; $this-&gt;url-&gt;link('common/home', '&amp;token=' . $this-&gt;session-&gt;data['token'], 'SSL'),
       'separator' =&gt; false
  
    ); 
    $this-&gt;data['breadcrumbs'][] = array(
       'text' =&gt; $this-&gt;language-&gt;get('heading_title'),
       'href' =&gt; $this-&gt;url-&gt;link('information/news', '&amp;token=' . $this-&gt;session-&gt;data['token'], 'SSL'),//to the table
       'separator' =&gt; $this-&gt;language-&gt;get('text_separator')
    );
     $this-&gt;data['cancel'] = $this-&gt;url-&gt;link('information/news', '&amp;token=' . $this-&gt;session-&gt;data['token'], 'SSL');
  
  
     if ($this-&gt;request-&gt;server['REQUEST_METHOD'] == 'POST' &amp;&amp; $this-&gt;validateForm($this-&gt;request-&gt;post['news']))//Data entered by the user  
         {
          $this-&gt;model_information_news-&gt;insert($this-&gt;request-&gt;post['news'],$this-&gt;session-&gt;data['user_id']);//Information is now sent to model. 
          $this-&gt;session-&gt;data['success'] = $this-&gt;language-&gt;get('text_success_insert');
          $this-&gt;redirect($this-&gt;url-&gt;link('information/news', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'));
          }
           $this-&gt;form();//form function call
      } 
  </code></pre>
  
  <p><code>Validation function</code></p>
  
  <pre><code>public function validateForm($news)
  {
  
  if (!$this-&gt;user-&gt;hasPermission('modify', 'catalog/category')) {
          $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_permission');
      }
  
   if((utf8_strlen(trim($news[1]['title']))==0)||(utf8_strlen(trim($news[1]['title']))&gt;250))
    $this-&gt;error['title']=$this-&gt;language-&gt;get('error_title');
  
    if($this-&gt;error)
     return false;
    else 
     return true;
   }
  </code></pre>
  
  <p><strong>form population function</strong></p>
  
  <pre><code>private function form() 
  {
      $this-&gt;load-&gt;language('information/news');
      $this-&gt;load-&gt;model('information/news');
      $this-&gt;load-&gt;model('localisation/language');
      $cityId = array();
      //Text from language file
      $this-&gt;data['text_title'] = $this-&gt;language-&gt;get('text_title');
      $this-&gt;data['text_description'] = $this-&gt;language-&gt;get('text_description');
      $this-&gt;data['text_image_manager'] = $this-&gt;language-&gt;get('text_image_manager');
      $this-&gt;data['text_image'] = $this-&gt;language-&gt;get('text_image');
      $this-&gt;data['text_browse'] = $this-&gt;language-&gt;get('text_browse');
      $this-&gt;data['text_clear'] = $this-&gt;language-&gt;get('text_clear');
      $this-&gt;data['text_city'] = $this-&gt;language-&gt;get('text_city');
  
      $this-&gt;data['button_submit'] = $this-&gt;language-&gt;get('button_submit');
      $this-&gt;data['button_cancel'] = $this-&gt;language-&gt;get('button_cancel');
  
      $this-&gt;data['tab_general'] = $this-&gt;language-&gt;get('tab_general');
      $this-&gt;data['languages'] = $this-&gt;model_localisation_language-&gt;getLanguages();
      $this-&gt;data['token'] = $this-&gt;session-&gt;data['token'];
      $this-&gt;document-&gt;setTitle($this-&gt;language-&gt;get('heading_title'));
  
       if (isset($this-&gt;error['title'])) 
          $this-&gt;data['error_title'] = $this-&gt;error['title'];
      else 
          $this-&gt;data['error_title'] = '';
  
      if (isset($this-&gt;error['warning'])) {
          $this-&gt;data['error_warning'] = $this-&gt;error['warning'];
      } else {
          $this-&gt;data['error_warning'] = '';
      }
  
      if (isset($this-&gt;request-&gt;get['news_id'])) //obtaing all the news details.
      { 
         $this-&gt;data['news'] = $this-&gt;model_information_news-&gt;getNews($this-&gt;request-&gt;get['news_id']);
  
         $cityList = $this-&gt;model_information_news-&gt;getAdsCities($this-&gt;request-&gt;get['news_id']);
  
         foreach($cityList as $city)
         {
              $cityId[]=$city['city_id'];
         }
         $cityId = implode(",",$cityId);
         $this-&gt;data['news']['hidcity']=$cityId;
  
  
      }
      else
      { 
          $this-&gt;data['news']= '';
      }   
      $this-&gt;data['cityOptions'] = $this-&gt;generateCities();
      if (isset($this-&gt;request-&gt;post['title'])) {
          $this-&gt;data['title'] = $this-&gt;request-&gt;post['title'];
      } else {    
          $this-&gt;data['title'] = '';
      }
  
  
      if (isset($this-&gt;request-&gt;post['image'])) {
          $this-&gt;data['image'] = $this-&gt;request-&gt;post['image'];
      } elseif (!empty($this-&gt;data['news'])) {
          $this-&gt;data['image'] = $this-&gt;data['news']['image'];
      } else {
          $this-&gt;data['image'] = '';
      }
  
      $this-&gt;load-&gt;model('tool/image');
  
      if (isset($this-&gt;request-&gt;post['image']) &amp;&amp; file_exists(DIR_IMAGE . $this-&gt;request-&gt;post['image'])) {
          $this-&gt;data['thumb'] = $this-&gt;model_tool_image-&gt;resize($this-&gt;request-&gt;post['image'], 100, 100);
      } elseif (!empty($this-&gt;data['news']) &amp;&amp; $this-&gt;data['news']['image'] &amp;&amp; file_exists(DIR_IMAGE . $this-&gt;data['news']['image'])) {
          $this-&gt;data['thumb'] = $this-&gt;model_tool_image-&gt;resize( $this-&gt;data['news']['image'], 100, 100);
      } else {
          $this-&gt;data['thumb'] = $this-&gt;model_tool_image-&gt;resize('no_image.jpg', 100, 100);
      }
  
      $this-&gt;data['no_image'] = $this-&gt;model_tool_image-&gt;resize('no_image.jpg', 100, 100);
  
  
  $this-&gt;children = array(
          'common/header',
          'common/footer'
      );
      $this-&gt;response-&gt;setOutput($this-&gt;render());
  }
  </code></pre>
  
  <p>When I submit the form and if gets any validation error then all fields becomes cleared.</p>