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">×</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