0

I have a problem when add a custom tabs in order view. In new tabs, I have html form:

<form action="<?php echo $block->getUrl('giftvoucheradmin/giftvoucher/addcodetoorder') ?>" method="POST">               
            // something in here
</form>

However, when I click button it alway redirect to admin dashboard. I have try view console and coppy this url and open another window then action work well May I help you? Thank you.

1 Answer 1

0

I think this is Helpful for you,

Update your template with formkey:

<form action="<?php echo $block->getUrl('giftvoucheradmin/giftvoucher/addcodetoorder') ?>" method="POST">               
            // something in here

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

Add getFormKey() into you block

public function getFormKey(){

    return $this->formKey->getFormKey();
}

Reference: https://github.com/magento/magento2/blob/6ea7d2d85cded3fa0fbcf4e7aa0dcd4edbf568a6/app/code/Magento/Backend/view/adminhtml/templates/admin/formkey.phtml

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.