Skip to content

Form key validation

Can’t succeed to make a post frontend form to work

<form class="form"
      name="download-form"
      action="<?= $block->getUrl('booklets/booklet/email') ?>"
      method="post"
      data-mage-init='{"validation": {}}'
>
    <?= $block->getBlockHtml('formkey') ?>

src/vendor/magento/framework/Data/Form/FormKey/Validator.php

/**
 * Validate form key
 *
 * @param MagentoFrameworkAppRequestInterface $request
 * @return bool
 */
public function validate(MagentoFrameworkAppRequestInterface $request)
{
    $formKey = $request->getParam('form_key', null);
    var_dump($formKey);
    var_dump($this->_formKey->getFormKey());
    die();
    return $formKey && Security::compareStrings($formKey, $this->_formKey->getFormKey());
}

string(16) “snl3roMAhQAEzOZ0”

string(16) “AnyBlApmEuNXiUII”

My block extends

MagentoFrameworkViewElementTemplate;