0

I have a form with several inputs.(text and file).

    <form id="form-configurator" class="form-configurator " name="formconfigurator" action="index/toto" method="post" enctype="multipart/form-data">
       <input id="input-file" name="file" type="file" class="input-text required-entry" accept=".txt"></input>
       <input id="input-foo" name="foo" type="text" class="input-text required-entry"></input>
       <input id="input-bar" name="bar" type="number" class="input-text required-entry"></input>
       <input name="submit" value="the Name" type="submit" class="button nav-anchor" id="OrderButton"></input>
    </form>

The form submission calls a controller in which I manage to get the form parameters. At the end of the controller execution, I have redirect it to another page :

class toto extends \Magento\Framework\App\Action\Action
{
    protected $_resultPageFactory;
    protected $_resulFactory;


    public function __construct(
            \Magento\Framework\App\Action\Context $context,
            \Magento\Framework\View\Result\PageFactory $resultPageFactory,
            \Magento\Framework\Controller\ResultFactory $resulFactory,
            )
    {
        parent::__construct($context);
        $this->_resultPageFactory = $resultPageFactory;
        $this->_resultFactory = $resulFactory;
    }

    public function execute()
    {
        $post = $this->getRequest()->getPost();
    ....
    $resultRedirect = $this->_resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
                $resultRedirect->setPath('foo.html');
                return $resultRedirect;
}

The redirection works but I do not manage to pass parameters.

(I found an alternative solution by adding to the url ?params=, but i would like them to be hidden like in POST)

Thank you for your help

1
  • are you sending form using Ajax ? or put your full code which yo are using. Sep 10 '18 at 9:26
1

You can use the below code to pass parameters to any urls:

$param = ['param1' => 'value1', 'param2' => 'value2'];
$resultRedirect->setPath('frontname/path/controllername', ['params' => $params]);
0

I found the equivalent way for this :

You can use the session for it.

class toto extends \Magento\Framework\App\Action\Action
{
    protected $_resultPageFactory;
    protected $_resulFactory;


    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory,
        \Magento\Framework\Controller\ResultFactory $resulFactory,
        \Magento\Framework\Session\SessionManagerInterface $coreSession)
    {
        parent::__construct($context);
        $this->_resultPageFactory = $resultPageFactory;
        $this->_resultFactory = $resulFactory;
        $this->_coreSession = $coreSession;
    }

    public function execute()
    {
        $post = $this->getRequest()->getPost();

        $this->_coreSession->setValue(<<Set your value>>);

        $resultRedirect = $this->_resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
        $resultRedirect->setPath('foo.html');
        return $resultRedirect;
}

Now you can get your params value in any controller, block or page. And also more session class is available you can use it.

By this way we can set custom values:

  • \Magento\Backend\Model\Session
  • \Magento\Catalog\Model\Session
  • \Magento\Checkout\Model\Session
  • \Magento\Customer\Model\Session
  • \Magento\Newsletter\Model\Session

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.