title: Display alert message and redirect after click on accept
body: <p>I have a page with links to reports. Whenever somebody clicks on one report, they can download the excel file. However, sometimes there are no fields to make a report; in that case, I want to display an alert message and after they click on &quot;accept&quot;, they get redirected to the main panel. When they click on the report, they go to a controller that uses a <code>switch</code> to get the data. If there's no data, the model returns <code>FALSE</code>; so at the end of the controller, I check:</p>
  <pre><code>if ($result_array != FALSE)
      to_excel($result_array-&gt;result_array(), $xls,$campos);
  else {
      echo &quot;&lt;script&gt;alert('There are no fields to generate a report');&lt;/script&gt;&quot;;
      redirect('admin/ahm/panel');
  }
  </code></pre>
  <p>If I get rid of <code>redirect('admin/ahm/panel');</code> then the alert works, but it moves the user to the page that was supposed to generate the excel file. But if I use the redirect, the controller moves the user to the main panel without showing the alert.</p>