Skip to content

magento 2.4.3 Request validation failed for action “ControllerAdminhtmlImportSave

4.3 admin custom controller redirecting to dashboard

<form enctype="multipart/form-data" method="post" action="<?php echo $block->getFormAction(); ?>" id="edit_form" X-Requested-With= "XMLHttpRequest">
    <input name="form_key" type="hidden" value="<?php echo $block->updateCancelTime() ?>" />
            <!--<input name="form_key" type="hidden" value="<?php //  echo $block->getFormKey() ?>" />-->
    <div id="base_fieldset" class="fieldset ">
        <table>
            <tbody>
                <tr>
                    <td class="value">
                        <p class="import_file_child">
                            <label for="import_file_src-upload">
                                Upload File: <input type="file" class="fileupload" required title="Select File to Import" name="import_file" id="import_file">
                            </label>
                        </p>
                    </td>
                </tr>
                <tr>
                    <td class="value">
                        <p class="form-buttons">
                            <input class="save" type="submit" title="Submit" id="upload_button" value="Import"/>
                        </p>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</form>

my save controller

 namespace PawanIntraImportControllerAdminhtmlImport;

//use MagentoFrameworkAppActionHttpPostActionInterface;
use MagentoFrameworkAppActionHttpPostActionInterface as HttpPostActionInterface;
use MagentoBackendAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkRegistry;

class Save extends MagentoBackendAppAction implements HttpPostActionInterface
{
    
//    protected $importer;
//    protected $formKeyValidator;
//    protected $directoryList;
//
//    public function __construct(
//        Context $context,
//        MagentoFrameworkDataFormFormKeyValidator $formKeyValidator,
//      
//        MagentoFrameworkFilesystemDirectoryList $directoryList
//    ) {
//        $this->directoryList = $directoryList;
//      
//        $this->formKeyValidator = $formKeyValidator;
//        parent::__construct($context);
//    }

    /**
     * Save action
     *
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @return MagentoFrameworkControllerResultInterface
     */
    public function execute()
    {
        die("test reached controller");

 }
}

when I click on import button it redirecting to dashboard expected it redirect save file and print data but nor printing
in debug log getting

Request validation failed for action "PawanIntraImportControllerAdminhtmlImportSaveInterceptor

any one help that would be very helpful for me.in 2.3 it working fine but after upgrade it not working

https://www.generacodice.com/en/articolo/2983658/magento-2.3-upgrade-breaks-http-post-requests-to-custom-module-endpoint

checked this link also but no luck