0

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?

  • Are you sure that it is a valid php class?? because I can see closing and opening parts of php i.e ?> and <?php. I never did this and I highly doubt it is as correct way. I think the old link post is referring to a template file i.e .phtml but not .php. – Mr_Green May 20 '14 at 12:38
  • so then you are saying that it would be better to create my own .phtml file and then load it in my controller file? – user6398 May 20 '14 at 12:57
0

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.