0

I have a phtml template that display the formkey in my html file. Below is how I'm displaying this

<form action=""
      method="post"
      id="form-validate-pound"      
      class="form form-cart">

     <?= $block->getBlockHtml('formkey') ?>

      <button type="submit"
       name="click_for_pound_action"
       data-cart-empty=""
       value="click_pound"
       title="<?= $block->escapeHtml(__('Click for Pound')) ?>"
       class="action clear btn btn-yellow" id="click_pound_button">
           <span><?= $block->escapeHtml(__('Click for Pound')) ?>
               <i class="fa fa-plus"></i>
           </span>
      </button>
</form>

So basically I need to display <?= $block->getBlockHtml('formkey') ?> in my knockoutjs template. Below I need to display it in this html file

<form action=""
      method="post"
      id="form-validate-pound"
      class="form form-cart">

  <!-- DISPLAY THE FORMKEY HERE -->

      <button type="submit"
       name="click_for_pound_action"
       data-cart-empty=""
       value="click_pound"
       title="<?= $block->escapeHtml(__('Click for Pound')) ?>"
       class="action clear btn btn-yellow" id="click_pound_button">
      <span>
       <!-- ko i18n: 'Click for Pound'--><!-- /ko -->
         <i class="fa fa-plus"></i>
      </span>
   </button>
</form>
0

This is how the core achieves this:

Javascript

file: vendor/magento/module-checkout/view/frontend/web/js/view/payment.js:98

getFormKey: function () {
            return window.checkoutConfig.formKey;
}

HTML

file: vendor/magento/module-checkout/view/frontend/web/template/payment.html:19

<form id="co-payment-form" class="form payments" novalidate="novalidate">
    <input data-bind='attr: {value: getFormKey()}' type="hidden" name="form_key"/>
            ...
</form>
| improve this answer | |

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.