Custom form in backend is redirecting to /adminForm field custom backendTrying to run an AJAX script from the admin area in magentoMagento 2.1: Do we need to do anything special for the controll action to accept HTTP Post with Json Payload?Magento 2: How to override newsletter Subscriber modelMagento 2 : How can I upload files of dynamically added file input fields in the adminMagento 2 Add new field to Magento_User admin formHow to override contact us post action using plugin Magento 2Magento 2: I Want to add multiple product using checkboxHow to create custom form in Magento 2.2.3Magento 2 - Create csv file for download in admin

On the feasibility of space battleships

Is it safe to remove the bottom chords of a series of garage roof trusses?

What is this symbol: semicircles facing eachother

When translating the law, who ensures that the wording does not change the meaning of the law?

Ask for a paid taxi in order to arrive as early as possible for an interview within the city

Are required indicators necessary for radio buttons?

What magic extends life or grants immortality

Is a butterfly one or two animals?

What is wrong about this application of Kirchhoffs Current Law?

Why is observed clock rate < 3MHz on Arduino Uno?

Check in to 2 hotels at same location

Science fiction short story where aliens contact a drunk about Earth's impending destruction

Why we don't have vaccination against all diseases which are caused by microbes?

How does turbine efficiency compare with internal combustion engines if all the turbine power is converted to mechanical energy?

Efficiently pathfinding many flocking enemies around obstacles

Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")

Why aren't RCS openings an issue for spacecraft heat shields?

Was Tuvok bluffing when he said that Voyager's transporters rendered the Kazon weapons useless?

How do I find the fastest route from Heathrow to an address in London using all forms of transport?

Do AT motherboards (286, 386, 486) really need -5V (besides redirecting it to ISA connectors)?

Is refusing to concede in the face of an unstoppable Nexus combo punishable?

Why did this happen to Thanos's ships at the end of "Avengers: Endgame"?

Does an object count as "being moved" when placed in a Bag of Holding before its wielder moves, and then after moving they take the object out again?

Avoiding racist tropes in fantasy



Custom form in backend is redirecting to /admin


Form field custom backendTrying to run an AJAX script from the admin area in magentoMagento 2.1: Do we need to do anything special for the controll action to accept HTTP Post with Json Payload?Magento 2: How to override newsletter Subscriber modelMagento 2 : How can I upload files of dynamically added file input fields in the adminMagento 2 Add new field to Magento_User admin formHow to override contact us post action using plugin Magento 2Magento 2: I Want to add multiple product using checkboxHow to create custom form in Magento 2.2.3Magento 2 - Create csv file for download in admin






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I've created a custom form in my backend.



I can access it via /admin/export/export/index.



But when I submit my form, Magento is redirecting me to my admin home page. My form needs only to have 1 button to trigger the export of some data.



See my phtml :



<form method="POST" action="<?php echo $block->getUrl('export/export/index')?>">
<input type="hidden" name="action" value="export">
<button type="submit">Exporter les données</button>
</form>


and my controler :



 public function execute()

if('POST' == $this->getRequest()->getMethod()) //not going inside
die("post");
$this->_redirect('/admin/export/export/index');


$this->_view->loadLayout();
$this->_view->renderLayout();










share|improve this question






























    0















    I've created a custom form in my backend.



    I can access it via /admin/export/export/index.



    But when I submit my form, Magento is redirecting me to my admin home page. My form needs only to have 1 button to trigger the export of some data.



    See my phtml :



    <form method="POST" action="<?php echo $block->getUrl('export/export/index')?>">
    <input type="hidden" name="action" value="export">
    <button type="submit">Exporter les données</button>
    </form>


    and my controler :



     public function execute()

    if('POST' == $this->getRequest()->getMethod()) //not going inside
    die("post");
    $this->_redirect('/admin/export/export/index');


    $this->_view->loadLayout();
    $this->_view->renderLayout();










    share|improve this question


























      0












      0








      0








      I've created a custom form in my backend.



      I can access it via /admin/export/export/index.



      But when I submit my form, Magento is redirecting me to my admin home page. My form needs only to have 1 button to trigger the export of some data.



      See my phtml :



      <form method="POST" action="<?php echo $block->getUrl('export/export/index')?>">
      <input type="hidden" name="action" value="export">
      <button type="submit">Exporter les données</button>
      </form>


      and my controler :



       public function execute()

      if('POST' == $this->getRequest()->getMethod()) //not going inside
      die("post");
      $this->_redirect('/admin/export/export/index');


      $this->_view->loadLayout();
      $this->_view->renderLayout();










      share|improve this question














      I've created a custom form in my backend.



      I can access it via /admin/export/export/index.



      But when I submit my form, Magento is redirecting me to my admin home page. My form needs only to have 1 button to trigger the export of some data.



      See my phtml :



      <form method="POST" action="<?php echo $block->getUrl('export/export/index')?>">
      <input type="hidden" name="action" value="export">
      <button type="submit">Exporter les données</button>
      </form>


      and my controler :



       public function execute()

      if('POST' == $this->getRequest()->getMethod()) //not going inside
      die("post");
      $this->_redirect('/admin/export/export/index');


      $this->_view->loadLayout();
      $this->_view->renderLayout();







      magento2 admin forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 9 at 15:18









      Morgan TartreauMorgan Tartreau

      4665 silver badges17 bronze badges




      4665 silver badges17 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          3













          You are getting this error because all of the post requests need to have a valid form_key value sent.



          try adding this inside your form tag.



          <?= $block->getLayout()->getBlock('form_key');?>


          BUt I'm not sure if that works for admin forms.



          If that does not work, try this:

          add this in the block that renders the form



          private $formKey;

          public function __construct(
          ...
          MagentoFrameworkDataFormFormKey $formKey,
          ....
          )
          ....
          $this->formKey = $formKey;


          public function getFormKey()

          return $this->formKey->getFormKey();



          Now you can add this to your form



          <input type="hidden" name="form_key" value="<?= $block->getFormKey();?>" />





          share|improve this answer

























          • Yes, that's it !

            – Morgan Tartreau
            Aug 9 at 15:55











          • which one? I haven't tested any of them. The short one or the long one?

            – Marius
            Aug 9 at 16:08











          • Not tested yet, but I've tried to add the key in ajax form (by getting the key thourhg the url), and the ajax is working (I'll let you know which one is working)

            – Morgan Tartreau
            Aug 12 at 8:50













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f285021%2fcustom-form-in-backend-is-redirecting-to-admin%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3













          You are getting this error because all of the post requests need to have a valid form_key value sent.



          try adding this inside your form tag.



          <?= $block->getLayout()->getBlock('form_key');?>


          BUt I'm not sure if that works for admin forms.



          If that does not work, try this:

          add this in the block that renders the form



          private $formKey;

          public function __construct(
          ...
          MagentoFrameworkDataFormFormKey $formKey,
          ....
          )
          ....
          $this->formKey = $formKey;


          public function getFormKey()

          return $this->formKey->getFormKey();



          Now you can add this to your form



          <input type="hidden" name="form_key" value="<?= $block->getFormKey();?>" />





          share|improve this answer

























          • Yes, that's it !

            – Morgan Tartreau
            Aug 9 at 15:55











          • which one? I haven't tested any of them. The short one or the long one?

            – Marius
            Aug 9 at 16:08











          • Not tested yet, but I've tried to add the key in ajax form (by getting the key thourhg the url), and the ajax is working (I'll let you know which one is working)

            – Morgan Tartreau
            Aug 12 at 8:50















          3













          You are getting this error because all of the post requests need to have a valid form_key value sent.



          try adding this inside your form tag.



          <?= $block->getLayout()->getBlock('form_key');?>


          BUt I'm not sure if that works for admin forms.



          If that does not work, try this:

          add this in the block that renders the form



          private $formKey;

          public function __construct(
          ...
          MagentoFrameworkDataFormFormKey $formKey,
          ....
          )
          ....
          $this->formKey = $formKey;


          public function getFormKey()

          return $this->formKey->getFormKey();



          Now you can add this to your form



          <input type="hidden" name="form_key" value="<?= $block->getFormKey();?>" />





          share|improve this answer

























          • Yes, that's it !

            – Morgan Tartreau
            Aug 9 at 15:55











          • which one? I haven't tested any of them. The short one or the long one?

            – Marius
            Aug 9 at 16:08











          • Not tested yet, but I've tried to add the key in ajax form (by getting the key thourhg the url), and the ajax is working (I'll let you know which one is working)

            – Morgan Tartreau
            Aug 12 at 8:50













          3












          3








          3







          You are getting this error because all of the post requests need to have a valid form_key value sent.



          try adding this inside your form tag.



          <?= $block->getLayout()->getBlock('form_key');?>


          BUt I'm not sure if that works for admin forms.



          If that does not work, try this:

          add this in the block that renders the form



          private $formKey;

          public function __construct(
          ...
          MagentoFrameworkDataFormFormKey $formKey,
          ....
          )
          ....
          $this->formKey = $formKey;


          public function getFormKey()

          return $this->formKey->getFormKey();



          Now you can add this to your form



          <input type="hidden" name="form_key" value="<?= $block->getFormKey();?>" />





          share|improve this answer













          You are getting this error because all of the post requests need to have a valid form_key value sent.



          try adding this inside your form tag.



          <?= $block->getLayout()->getBlock('form_key');?>


          BUt I'm not sure if that works for admin forms.



          If that does not work, try this:

          add this in the block that renders the form



          private $formKey;

          public function __construct(
          ...
          MagentoFrameworkDataFormFormKey $formKey,
          ....
          )
          ....
          $this->formKey = $formKey;


          public function getFormKey()

          return $this->formKey->getFormKey();



          Now you can add this to your form



          <input type="hidden" name="form_key" value="<?= $block->getFormKey();?>" />






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 9 at 15:54









          MariusMarius

          172k30 gold badges334 silver badges709 bronze badges




          172k30 gold badges334 silver badges709 bronze badges















          • Yes, that's it !

            – Morgan Tartreau
            Aug 9 at 15:55











          • which one? I haven't tested any of them. The short one or the long one?

            – Marius
            Aug 9 at 16:08











          • Not tested yet, but I've tried to add the key in ajax form (by getting the key thourhg the url), and the ajax is working (I'll let you know which one is working)

            – Morgan Tartreau
            Aug 12 at 8:50

















          • Yes, that's it !

            – Morgan Tartreau
            Aug 9 at 15:55











          • which one? I haven't tested any of them. The short one or the long one?

            – Marius
            Aug 9 at 16:08











          • Not tested yet, but I've tried to add the key in ajax form (by getting the key thourhg the url), and the ajax is working (I'll let you know which one is working)

            – Morgan Tartreau
            Aug 12 at 8:50
















          Yes, that's it !

          – Morgan Tartreau
          Aug 9 at 15:55





          Yes, that's it !

          – Morgan Tartreau
          Aug 9 at 15:55













          which one? I haven't tested any of them. The short one or the long one?

          – Marius
          Aug 9 at 16:08





          which one? I haven't tested any of them. The short one or the long one?

          – Marius
          Aug 9 at 16:08













          Not tested yet, but I've tried to add the key in ajax form (by getting the key thourhg the url), and the ajax is working (I'll let you know which one is working)

          – Morgan Tartreau
          Aug 12 at 8:50





          Not tested yet, but I've tried to add the key in ajax form (by getting the key thourhg the url), and the ajax is working (I'll let you know which one is working)

          – Morgan Tartreau
          Aug 12 at 8:50

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f285021%2fcustom-form-in-backend-is-redirecting-to-admin%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?