I have created a custom module.

and I want on Save

<form action="<?php echo $block->getBaseUrl() . 'sales/order/view'; ?> " method="post" enctype="multipart/form-data">

On button click the form should call controller in which I can handle all posted data.

I have tried call controller using basepath, but it always redirect me to admin dashboard.

class Comment extends \Magento\Sales\Block\Adminhtml\Order\View\Info 

* Core registry 
* @var \Magento\Framework\Registry 
protected $coreRegistry = null; 

public function __construct( 
FormKey $formKey, \Magento\Backend\Block\Template\Context $context, 
\Magento\Framework\Registry $registry, 
\Magento\Sales\Helper\Admin $adminHelper, 
\Magento\Customer\Api\GroupRepositoryInterface $groupRepository, 
\Magento\Customer\Api\CustomerMetadataInterface $metadata, 
\Magento\Customer\Model\Metadata\ElementFactory $elementFactory, 
\Magento\Sales\Model\Order\Address\Renderer $addressRenderer, 
array $data = [] 
$this->coreRegistry = $registry; 
$this->formkey = $formKey; 
$this->_isScopePrivate = true; 
$this->_template = 'order/view/comment.phtml'; 
parent::__construct($context,$registry,$adminHelper, $groupRepository,$metadata,$elementFactory, $addressRenderer,$data); 

public function getFormKey() 
return $this->formkey->getFormKey(); 

public function getCurrentOrder(): Order 
return $this->coreRegistry->registry('current_order'); 

public function getOrderComment(): string
    return trim($this->getCurrentOrder()->getData(OrderComment::COMMENT_FIELD_NAME));
  • Please check update in chat Commented Feb 7, 2018 at 8:46

1 Answer 1


Instead of $block->getBaseUrl() use $block->getUrl() to get the url and for the form submit you have to add formkey as a hidden input. try below solution.

<form action="<?php echo $block->getUrl('*/*/view') ?>" method="post" enctype="multipart/form-data">

This will call current module's View controller if you want another sales/order/view controller then use below action.

 <form action="<?php echo $block->getUrl('sales/order/view') ?>" method="post" enctype="multipart/form-data">

and after that add this hidden input in your form.

 <input name="form_key" value="<? echo $block->getFormKey()?>" type="hidden"/>


<form action="<?php echo $block->getUrl('*/*/view',['order_id'=>$your_order_id]) ?>" method="post" enctype="multipart/form-data">
  • its return "This order no longer exists" error
    – Mahi M
    Commented Feb 7, 2018 at 5:32
  • Do you want to edit particular order? Commented Feb 7, 2018 at 5:33
  • yes........edit custom input field in order
    – Mahi M
    Commented Feb 7, 2018 at 5:35
  • see my updated answer. Commented Feb 7, 2018 at 5:39
  • Can you please check if you get current order from registry? Commented Feb 7, 2018 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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