title: Magento Admin form redirects to dashboard on ?post?
body: <p>Magento 1.7.0.2: 
  I'm trying to get a form (in the backend) to upload a file(picture) to Post to itself if incomplete, or the adminhtml controller if complete. My JavaScript validation is working well, but when/if my form is POSTed I'm redirected to the dashboard. I've got a form key included and my url's are created with the special key, but still I can't get a POST through. Can anyone help me?</p>
  
  <p>The phtml template file:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function postSelf(){
      form=document.getElementById('imgSel');
      form.action='&lt;?php Mage::helper("adminhtml")-&gt;getUrl("*/*/")?&gt;';
      form.submit();
  }    
  function validateForm(){
  
      var name=document.forms["imgSel"]["iName"].value;
      var file=document.forms["imgSel"]["file_upload"].value;
      if (!name){
          alert("You must have an Image Name!");
          postSelf();
      }
      else if (!file){
          alert("You must have a File to upload");
          postSelf();
      }
      else{
          form=document.getElementById('imgSel');
          form.submit();
      } 
  }  
      &lt;/script&gt;
  
      &lt;?php Mage::log(Mage::helper("adminhtml")-&gt;getUrl("*/*/"), null, ‘layout.log’ );?&gt;
  
  &lt;h3 class="icon-head head-adminhtml-imagegrid"&gt;Add an Image:&lt;/h3&gt;
  
  &lt;form name="imgSel" id="imgSel" action="&lt;?php Mage::helper("adminhtml")-&gt;getUrl("*/*/insert")?&gt;" 
        enctype="multipart/form-data" method="POST"&gt;
  &lt;!--Form key--&gt;
      &lt;input type="hidden" name="form_key" value="&lt;? echo Mage::getSingleton('core/session')-&gt;getFormKey(); ?&gt;" /&gt;
      &lt;?php Mage::log(Mage::getSingleton('core/session')-&gt;getFormKey(), null, ‘layout.log’ );?&gt;
  
      &lt;label for="iName"&gt;Image Name:&lt;/label&gt;
      &lt;input type="text" name="iName"&gt;
  
      &lt;label for="style"&gt;Associated Style Name:&lt;/label&gt;
      &lt;select name="style"&gt;
      &lt;?php
      echo '&lt;option value="-1"&gt;None&lt;/option&gt;';
      $styles = Mage::getModel('cartonplugin/cartonstyle')-&gt;getCollection();
      foreach($styles as $style){
          echo '&lt;option value="'.$style-&gt;getId().'"';
          echo '&gt;'.$style-&gt;getData('style_name').'&lt;/option&gt; ';
      }
      echo '&lt;/select&gt;&lt;br /&gt;';
      ?&gt;
      &lt;input type="hidden" name="MAX_FILE_SIZE" value="40" /&gt;
      Upload Image: &lt;input type="file" name="file_upload" /&gt;
      &lt;br&gt;
      &lt;!--&lt;input type="submit" value="submit"&gt;--&gt;
      &lt;button onClick="validateForm()" class="UploadButton" &gt;Upload&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Controller: Only the insertAction() function is for this form. The rest is gridview stuff for dealing with any already-uploaded images.</p>
  
  <pre><code>&lt;?php
  class Nationwide_Newcart_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
  {
      protected function _initAction()
      {
          $this-&gt;loadLayout()-&gt;_setActiveMenu('igrid/set_time7')
                  -&gt;_addBreadcrumb('image Manager','image Manager');
         return $this;
       }
  
      public function indexAction()
      {
          $this-&gt;loadLayout();
          $this-&gt;renderLayout();
  
          //var_dump(Mage::getSingleton('core/layout')-&gt;getUpdate()-&gt;getHandles());
       }
  
        public function newAction()
      {
          $this-&gt;_forward('edit');
      }
  
      public function editAction()
      {
          $stId = $this-&gt;getRequest()-&gt;getParam('id');
          $model = Mage::getModel('newcart/imagemodel')-&gt;load($stId);
          if ($model-&gt;getId() || $stId == 0)
             {
               Mage::register('image_data', $model);
               $this-&gt;loadLayout();
               $this-&gt;_setActiveMenu('igrid/set_time7');
               $this-&gt;_addBreadcrumb('image Manager', 'image Manager');
               $this-&gt;_addBreadcrumb('Image Description', 'Image Description');
               $this-&gt;getLayout()-&gt;getBlock('head')
                    -&gt;setCanLoadExtJs(true);
               $this-&gt;_addContent($this-&gt;getLayout()
                    -&gt;createBlock('newcart/adminhtml_imagegrid_edit'))
                    -&gt;_addLeft($this-&gt;getLayout()
                    -&gt;createBlock('newcart/adminhtml_imagegrid_edit_tabs')
                );
               $this-&gt;renderLayout();
             }
             else
             {
                   Mage::getSingleton('adminhtml/session')
                         -&gt;addError('That Image does not exist');
                   $this-&gt;_redirect('*/*/');
              }
         }
  
      public function saveAction()
      {
           if ($this-&gt;getRequest()-&gt;getPost())
           {
             try {
                  $postData = $this-&gt;getRequest()-&gt;getPost();
                  $model = Mage::getModel('');
                  //Mage::log($this-&gt;getRequest()-&gt;getParam('id'), null, ‘layout.log’ );
                  if( $this-&gt;getRequest()-&gt;getParam('id') &lt;= 0 )
                      $model-&gt;setCreatedTime(
                          Mage::getSingleton('core/date')
                                  -&gt;gmtDate()
                      );
                  $model
                      //-&gt;addData($postData) //DO NOT! Includes a form key!
                      -&gt;setUpdateTime(
                              Mage::getSingleton('core/date')
                              -&gt;gmtDate())
                      -&gt;setId($this-&gt;getRequest()-&gt;getParam('id'));
                  $model-&gt;setData('image_name', $postData['image_name']);
                  $model-&gt;setData('style_name', $postData['style_name']);
                  $model-&gt;save();
  
                  Mage::getSingleton('adminhtml/session')
                              -&gt;addSuccess('successfully saved');
                  Mage::getSingleton('adminhtml/session')
                                  -&gt;settestData(false);
                  $this-&gt;_redirect('*/*/');
                  return;
            } catch (Exception $e){
                  Mage::getSingleton('adminhtml/session')
                                    -&gt;addError($e-&gt;getMessage());
                  Mage::getSingleton('adminhtml/session')
                   -&gt;settestData($this-&gt;getRequest()
                                      -&gt;getPost()
                  );
                  $this-&gt;_redirect('*/*/edit',
                              array('id' =&gt; $this-&gt;getRequest()
                                                  -&gt;getParam('id')));
                  return;
                  }
                }
                $this-&gt;_redirect('*/*/');
              }
  
      public function deleteAction()
      {
          if($this-&gt;getRequest()-&gt;getParam('id') &gt; 0)
          {
              try
              {
                  $model = Mage::getModel('newcart/imagemodel');
                  $model-&gt;setId($this-&gt;getRequest()
                                      -&gt;getParam('id'))
                              -&gt;delete();
                  Mage::getSingleton('adminhtml/session')
                              -&gt;addSuccess('successfully deleted');
                  $this-&gt;_redirect('*/*/');
                  }
                  catch (Exception $e)
                  {
                          Mage::getSingleton('adminhtml/session')
                              -&gt;addError($e-&gt;getMessage());
                          $this-&gt;_redirect('*/*/edit', array('id' =&gt; $this-&gt;getRequest()-&gt;getParam('id')));
                  }
           }
              $this-&gt;_redirect('*/*/');
      }
  
      public function insertAction(){
          $postData = $this-&gt;getRequest()-&gt;getPost();
          Mage::log($postData, null, ‘layout.log’ );
  
          //post checking
          if(empty($postData)){
  
          }
  
          $this-&gt;_redirect('*/*/');
      }
  }
  </code></pre>