Magento Redirects to Admin Start Page on Custom Button Click

controllersformsmagento-1.7magento-1.8routing

in magento i have created a custom button in admin area that opens new pop up window, in this window i have form very similar like this in this post
Actually i want to do the same thing, like in that post, so here is my code:

class MyCompany_MyModule_Adminhtml_LabelController
extends Mage_Adminhtml_Controller_Action
{
    public function setlabelAction()
        {
           if (!isset($_POST['submit']))
           {
                 ?>
                   <html>
                       <h2>Select label size:</h2>        
                        <form action="LebelController.php" method="POST"><div>
                            <select name="SIZE">
                             <option value="1x1">1x1</option>
                              <option value="2x2">2x2</option>
                              <option value="3x3">3x3</option>
                              <option value="4x4">4x4</option>
                            </select>

                            <input type="submit" name="submit" value="Go">
                        </form>
                   </html>
           <?php
           }
           else 
           {
                echo ($_POST);
           }

when i click on my custom button the new popup window with form inside appears, but the problem is that if i choose value from this combobox and click on this form button "Go", magento opens admin start page(grid page?) in this popup window. I wonder why is this happening? why it goes there, and just not relods my popup window where the choosed value is echoed?

Best Answer

All admin POST requests require a form key that is session dependent. If that form key is not set then you get redirected to the dashboard or any other page that you set as default page.
Try adding this inside your form.

<input type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey()?>" name="form_key">

Also you shouldn't submit the form to LebelController.php. It doesn't work like that.
You have to submit it to an url with this form adminhtml/controller/action.

In your case you can get the url like this:

Mage::helper('adminhtml')->getUrl('adminhtml/label/setlabel')

Depending on how you built your module the url above might not work.
In this case try with

Mage::helper('adminhtml')->getUrl('mymodule/adminhtml_label/setlabel');