1

I am creating custom form in admin order detail page with form action as like below but it's redirecting to Dashboard from my action with 302.

My script is:

sales_order_view.xml

<?xml version="1.0"?>
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
    <referenceBlock name="order_additional_info">
        <block class="Sample\Serialcode\Block\Adminhtml\Order\View\Pdf" name="sales_order_view_pdf" template="order/view/pdf.phtml" />
    </referenceBlock>
  </body>
</page>

Phtml file:

<div class="modal">
<div class="modal-content">
    <span class="close">&times;</span>
    <form method="post" action="<?php echo $block->getUrl('sample/serialcode/index/');?>">
        <input type="hidden" name="orderid"  class="orderid" value="<?php //echo $incrementId?>"/>
        <!-- <input type="hidden" name="ishasparent" class="ishasparent" value=""/>
         <input type="hidden" name="sku" class="sku" value=""/>
         <input type="hidden" name="parentsku" class="parentsku" value=""/>
         <input type="hidden" name="missedSerialcodes" class="missedSerialcodes" value=""/>-->
        <label>Serial Codes </label><textarea rows="4" cols="30" name="newserialcodes"></textarea>
        <p style="color: red;display: none">Serial Codes are not empty</p>
        <p>Note: Each serial code seperated by '|' symbol like "121|122|123"</p>
        <button type="submit" class="form-submit">Submit</button>
    </form>
</div>

Block File:

namespace Sample\Serialcode\Block\Adminhtml\Order\View;

 use Magento\Backend\Block\Template;


 class Pdf extends Template
 {

protected $order;

protected $orderitemSerialcode;

protected $orderData;

public function __construct(Template\Context $context,
                            \Magento\Sales\Model\Order $order,
                            \Sample\Serialcode\Model\OrderitemSerialcode $orderitemSerialcode,
                            array $data = [])
{
    $this->orderData = array();
    $this->order = $order;
    $this->orderitemSerialcode = $orderitemSerialcode;
    parent::__construct($context, $data);
}

 }

My Controller:

namespace Sample\Serialcode\Controller\Adminhtml\Serialcode;

use Magento\Backend\App\Action;


class Index extends \Magento\Backend\App\Action{


    protected $orderObj;

    private $coreRegistry = null;

    private $resultPageFactory;

    private $backSession;

    protected $sage;

    public function __construct(Action\Context $context,
                                \Magento\Framework\View\Result\PageFactory $resultPageFactory,
                                \Magento\Framework\Registry $registry
                               ){

        $this->resultPageFactory = $resultPageFactory;
        $this->coreRegistry = $registry;
        $this->backSession = $context->getSession();

        parent::__construct($context);

    }


    public function execute(){
        echo  "hello";exit;           
    }
  }

routes.xml

Sample\Serialcode\etc\adminhtml\routes.xml

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
    <route id="sample" frontName="sample">
        <module name="Sample_Serialcode" />
    </route>
</router>

When i used this url for menu it's redirection but it's not working from order detail page

  • can you please update your question with routes.xml, please share path of this file as well. – Ramkishan Suthar Nov 14 '18 at 16:32
  • @RamkishanSuthar, i update code will you please check once & When i used this url for menu it's redirection but it's not working from order detail page – Ramesh Nov 14 '18 at 16:54
  • @Ramkishan, sorry to say that's my typing issue in editor. if i used same action from menu action it's redirecting...it's not working from order detail page – Ramesh Nov 15 '18 at 4:55
  • Have you tried the solution which I have given below? – Ramkishan Suthar Nov 15 '18 at 4:58
  • yes @RamkishanSuthar.... – Ramesh Nov 15 '18 at 5:08
1

@ Thanks Ramkishan Suthar

This is the issue with form key.

<input name="form_key" type="hidden" value="<?php / @escapeNotVerified / echo $block->getFormKey() ?>" />
| improve this answer | |
0

Please update routes.xml like below.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
    <route id="sample" frontName="sample">
        <module name="Sample_Serialcode" />
    </route>
</router>

Your module name should not start with lowercase. Let me know if you still face any issue.

| improve this answer | |
  • Did it help you? – Ramkishan Suthar Nov 14 '18 at 17:11
  • This is the issue with form key – Ramesh Nov 15 '18 at 6:30

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.