title: Error redirects for OpenCart with UserFrosting
body: <p>So I have been working on integrating OpenCart in to UserFrosting (<a href="http://www.userfrosting.com/" rel="nofollow">http://www.userfrosting.com/</a>). Basically I am making all the admin dashboard pages load in the UserFrosting dashboard by using <code>.load</code> to inject the pages into a <code>div</code> on my own html pages. I am almost finished but have one last piece to get working that isn't remaining within the UF dashboard.</p>
  
  <p>I will use the Catalog / Categories page as an example to show what I am doing:</p>
  
  <p>Here is my html file for categories, it's called <strong>cata-categories.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
          &lt;html lang="en"&gt;
          {% include 'components/head.html' %}
          &lt;script src="https://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
          &lt;body&gt;
              &lt;div id="wrapper"&gt;
                  {% include 'components/nav-account.html' %}
                  &lt;div id="page-wrapper"&gt;
                      {% include 'components/alerts.html' %}
  
                      &lt;ol id="categories"&gt;&lt;/ol&gt;
  
                  &lt;script&gt;
                      $( "#categories" ).load( "../solutions/admin/index.php?route=catalog/category" );
                  &lt;/script&gt;
  
  
  
                      &lt;br&gt;
                      {% include 'components/footer.html' %}    
                  &lt;/div&gt;
              &lt;/div&gt;&lt;/div&gt;
          &lt;/body&gt;
          &lt;/html&gt;
  </code></pre>
  
  <p>This is accessed via the sidebar of UserFrosting with the following code in <strong>sidebar.html</strong>:</p>
  
  <pre><code>{% if checkAccess('uri_manage_groups') %}
                  &lt;li&gt;
                      &lt;a href="{{site.uri.public}}/cata-categories/"&gt;&lt;i class="fa fa-tags fa-fw"&gt;&lt;/i&gt;Categories&lt;/a&gt;
                  &lt;/li&gt;
                  {% endif %}
  </code></pre>
  
  <p>The page is rendered via the following code in <strong>public/index.php</strong> for UserFrosting:</p>
  
  <pre><code> $app-&gt;get('/cata-categories/?', function () use ($app) {   
             $app-&gt;render('cata-categories.html', [
                 'page' =&gt; [
                     'author' =&gt;         $app-&gt;site-&gt;author,
                     'title' =&gt;          "Catagories",
                     'description' =&gt;    "Catalogue Catagories.",
                     'alerts' =&gt;         $app-&gt;alerts-&gt;getAndClearMessages()
                 ]
             ]);  
          });
  </code></pre>
  
  <p>To keep all links clicked on the OpenCart pages I put the following script on the bottom of each main <code>.tpl</code> (so for example <code>category_list.tpl</code>):</p>
  
  <pre><code>&lt;script&gt;
  $("#categories").on("click", "a", function (e) {
      $("#categories").load($(this).attr("href"));
      e.preventDefault();
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Then to keep things on the same page when submitting forms I changed the redirects in the controllers (eg. <strong>category.php</strong>) to be the following:</p>
  
  <pre><code>$this-&gt;response-&gt;redirect('../../portal/cata-categories');
  </code></pre>
  
  <p>Everything works great, now the only issue is errors in the form submission or filtering results. For example if someone tries to add a new category but doesn't fill in any information and clicks save, it redirects to <code>/admin/index.php?route=catalog/category/add</code> but not within the UserFrosting dashboard. </p>
  
  <p>I want it to remain within my dashboard, and need a nudge in the right direction on what to modify within the controller to get it to do this, I'm assuming some sort of AJAX to force it not to reload the page and just show the errors. Same thing with filter buttons, it obviously needs to add filters to the URL and therefore doesn't load within the dashboard - need a way to filter without refreshing.</p>
  
  <p>Any help from people with experience modifying OpenCart would be greatly appreciated and if you need any more info on what I am doing feel free to ask.</p>