Skip to content
Advertisement

Magento 2.4 Custom form post is redirecting 404 or search

I have problem with custom made form that should make post request to custom controller, it’s redirecting me to search page and i have no idea why. When i try to paste action url into browser it’s working corectlly.

my form phtml:

<form class="quick-order-list"
  method="post"
  action="<?php echo $block->getFormAction(); ?>"
  name="listsform"
  enctype='multipart/form-data'>
<?= $block->getChildHtml('quick_order_multipleskus') ?>
<?= $block->getChildHtml('quick_order_file') ?>
<div class="quick-order-list-button">
    <div class="secondary">
        <button type="submit"
                name="lists"
                title="<?= __('Add to List') ?>"
                class="action submit primary">
            <span><?= __('Add to List') ?></span>
        </button>
    </div>
</div>

get action method:

public function getFormAction()
{
    return $this->getUrl('quickorder/lists/index', ['_secure' => true]);
}

controller is located in vendormoduleControllerListsIndex.php file

<?php
declare(strict_types=1);

namespace modulevendorControllerLists;

use MagentoFrameworkAppActionHttpGetActionInterface;
use MagentoFrameworkControllerResultForward;
use MagentoFrameworkControllerResultForwardFactory;


class Index implements HttpGetActionInterface
{

private $forwardFactory;


public function __construct(
    ForwardFactory $forwardFactory
) {
    $this->forwardFactory = $forwardFactory;
}

public function execute()
{
    die('ello');
}
}

in html for me it looks ok:

<form class="quick-order-list" method="post" action="http://pleasehelp.local/quickorder/lists/index/" name="listsform" enctype="multipart/form-data">

after pressing submit i’m landing at: /catalogsearch/result/?q=quickorder+lists+index

Magento 2.4.0, php7.3

It’s not even landing in execute function, but i can catch it in constructor when i place die() there it’s working. Tried many thinks like, removing fields from form, trying to point to other controllers, placing static action url there,

for GET it’s working corecctly…

I starteed to suspect that it has nothing to do with my code but something is broken in project, but don’t know how to check it, can someone point me in correct direction ?

Advertisement

Answer

You should implements MagentoFrameworkAppActionHttpPostActionInterface instead of HttpGetActionInterface inside your controller class

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement