Magento 2.3: How to Echo From Controller On Button Click?Retreive and return response from controller in magento2How to call a model method from controller in Magento2Magento 2 “Recoverable Error: Argument 2 passed” when trying to define model in constructorI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2 Custom Module New Controller Issuegetting error in while running Cutom admin controller URL in magento 2Magento 2 : Problem while adding custom button order view page?Magento 2 admin form controller errorDI not working in ControllerMagento 2.2.5: Overriding Admin Controller sales/orderMagento 2.3 Can't view module's front end page output?

Smallest Guaranteed hash collision cycle length

Was this a power play by Daenerys?

Extrude the faces of a cube symmetrically along XYZ

Reaction of borax with NaOH

Surely they can fit?

Why was Endgame Thanos so different than Infinity War Thanos?

How does Howard Stark know this?

Why was Thor doubtful about his worthiness to Mjolnir?

Can I use my laptop, which says 100-240V, in the USA?

Proof that the inverse image of a single element is a discrete space

Two researchers want to work on the same extension to my paper. Who to help?

How to select certain lines (n, n+4, n+8, n+12...) from the file?

What are the components of a legend (in the sense of a tale, not a figure legend)?

Do atomic orbitals "pulse" in time?

What is the best way for a skeleton to impersonate human without using magic?

What does a comma mean inside an 'if' statement?

What to do if SUS scores contradict qualitative feedback?

SSD - Disk is OK, one bad sector

Create a list of all possible Boolean configurations of three constraints

How did Thanos not realise this had happened at the end of Endgame?

Size of a folder with du

A curve pass via points at TiKz

What is the significance of 4200 BCE in context of farming replacing foraging in Europe?

On studying Computer Science vs. Software Engineering to become a proficient coder



Magento 2.3: How to Echo From Controller On Button Click?


Retreive and return response from controller in magento2How to call a model method from controller in Magento2Magento 2 “Recoverable Error: Argument 2 passed” when trying to define model in constructorI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2 Custom Module New Controller Issuegetting error in while running Cutom admin controller URL in magento 2Magento 2 : Problem while adding custom button order view page?Magento 2 admin form controller errorDI not working in ControllerMagento 2.2.5: Overriding Admin Controller sales/orderMagento 2.3 Can't view module's front end page output?






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








1















I'm very new to Magento, I have a custom module and some tabs and fields in it, i have an 'import' tab, in that their is 'Import' button, just want to know the workflow of that button, like on button click just echo something from controller. Right now i'm getting no response on button click...



appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



<div class="pp-buttons-container">
<button id="<?php echo $block->getId() ?>" onclick="return false;">
<span><span><span><?php echo 'Import'; ?></span></span></span>
</button>
</div>
<script type="text/javascript">
require(["jquery",], function($)
"use strict";
$(document).on('click','.col-action-grouped a',function()
);
);
</script>


appcodeVendor_NameModule_NameBlockAdminhtmlFormEditTabImport.php



<?php
namespace ECCustomimportBlockAdminhtmlFormEditTab;


class Import extends MagentoBackendBlockWidgetFormGeneric implements MagentoBackendBlockWidgetTabTabInterface

protected $_template = 'form/import.phtml';

public function isReadonly()

return false;


public function getTabLabel()

return __('Import');


public function getTabTitle()

return __('Import');


public function canShowTab()

return true;


public function isHidden()

return false;




appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



<?php

namespace ECCustomimportControllerAdminhtmlIndex;

use ECCustomimportModelCustomimportFactory;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;

class Import extends MagentoBackendAppAction

/**
* @param Context $context
*/
public function __construct(
Context $context,
CustomimportFactory $modelCustomimportFactory
)
$this->modelCustomimportFactory = $modelCustomimportFactory;
$this->resultFactory = $context->getResultFactory();
parent::__construct($context);


public function execute()
ignore_user_abort(true);
set_time_limit(0);
$id = $this->getRequest()->getParam('id');
$model = $this->modelCustomimportFactory->create()->load($id);
$model->import();
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('adminhtml/*/index');
return $resultRedirect;




enter image description here










share|improve this question
























  • your calling getId() method but it is not in your block class. Also your onclick function does not do anything so sure you will not get a response from that

    – magefms
    May 8 at 10:04












  • you can check this on how to pass response from the controller to ajax magento.stackexchange.com/questions/138043/…

    – magefms
    May 8 at 10:09


















1















I'm very new to Magento, I have a custom module and some tabs and fields in it, i have an 'import' tab, in that their is 'Import' button, just want to know the workflow of that button, like on button click just echo something from controller. Right now i'm getting no response on button click...



appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



<div class="pp-buttons-container">
<button id="<?php echo $block->getId() ?>" onclick="return false;">
<span><span><span><?php echo 'Import'; ?></span></span></span>
</button>
</div>
<script type="text/javascript">
require(["jquery",], function($)
"use strict";
$(document).on('click','.col-action-grouped a',function()
);
);
</script>


appcodeVendor_NameModule_NameBlockAdminhtmlFormEditTabImport.php



<?php
namespace ECCustomimportBlockAdminhtmlFormEditTab;


class Import extends MagentoBackendBlockWidgetFormGeneric implements MagentoBackendBlockWidgetTabTabInterface

protected $_template = 'form/import.phtml';

public function isReadonly()

return false;


public function getTabLabel()

return __('Import');


public function getTabTitle()

return __('Import');


public function canShowTab()

return true;


public function isHidden()

return false;




appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



<?php

namespace ECCustomimportControllerAdminhtmlIndex;

use ECCustomimportModelCustomimportFactory;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;

class Import extends MagentoBackendAppAction

/**
* @param Context $context
*/
public function __construct(
Context $context,
CustomimportFactory $modelCustomimportFactory
)
$this->modelCustomimportFactory = $modelCustomimportFactory;
$this->resultFactory = $context->getResultFactory();
parent::__construct($context);


public function execute()
ignore_user_abort(true);
set_time_limit(0);
$id = $this->getRequest()->getParam('id');
$model = $this->modelCustomimportFactory->create()->load($id);
$model->import();
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('adminhtml/*/index');
return $resultRedirect;




enter image description here










share|improve this question
























  • your calling getId() method but it is not in your block class. Also your onclick function does not do anything so sure you will not get a response from that

    – magefms
    May 8 at 10:04












  • you can check this on how to pass response from the controller to ajax magento.stackexchange.com/questions/138043/…

    – magefms
    May 8 at 10:09














1












1








1








I'm very new to Magento, I have a custom module and some tabs and fields in it, i have an 'import' tab, in that their is 'Import' button, just want to know the workflow of that button, like on button click just echo something from controller. Right now i'm getting no response on button click...



appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



<div class="pp-buttons-container">
<button id="<?php echo $block->getId() ?>" onclick="return false;">
<span><span><span><?php echo 'Import'; ?></span></span></span>
</button>
</div>
<script type="text/javascript">
require(["jquery",], function($)
"use strict";
$(document).on('click','.col-action-grouped a',function()
);
);
</script>


appcodeVendor_NameModule_NameBlockAdminhtmlFormEditTabImport.php



<?php
namespace ECCustomimportBlockAdminhtmlFormEditTab;


class Import extends MagentoBackendBlockWidgetFormGeneric implements MagentoBackendBlockWidgetTabTabInterface

protected $_template = 'form/import.phtml';

public function isReadonly()

return false;


public function getTabLabel()

return __('Import');


public function getTabTitle()

return __('Import');


public function canShowTab()

return true;


public function isHidden()

return false;




appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



<?php

namespace ECCustomimportControllerAdminhtmlIndex;

use ECCustomimportModelCustomimportFactory;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;

class Import extends MagentoBackendAppAction

/**
* @param Context $context
*/
public function __construct(
Context $context,
CustomimportFactory $modelCustomimportFactory
)
$this->modelCustomimportFactory = $modelCustomimportFactory;
$this->resultFactory = $context->getResultFactory();
parent::__construct($context);


public function execute()
ignore_user_abort(true);
set_time_limit(0);
$id = $this->getRequest()->getParam('id');
$model = $this->modelCustomimportFactory->create()->load($id);
$model->import();
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('adminhtml/*/index');
return $resultRedirect;




enter image description here










share|improve this question
















I'm very new to Magento, I have a custom module and some tabs and fields in it, i have an 'import' tab, in that their is 'Import' button, just want to know the workflow of that button, like on button click just echo something from controller. Right now i'm getting no response on button click...



appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



<div class="pp-buttons-container">
<button id="<?php echo $block->getId() ?>" onclick="return false;">
<span><span><span><?php echo 'Import'; ?></span></span></span>
</button>
</div>
<script type="text/javascript">
require(["jquery",], function($)
"use strict";
$(document).on('click','.col-action-grouped a',function()
);
);
</script>


appcodeVendor_NameModule_NameBlockAdminhtmlFormEditTabImport.php



<?php
namespace ECCustomimportBlockAdminhtmlFormEditTab;


class Import extends MagentoBackendBlockWidgetFormGeneric implements MagentoBackendBlockWidgetTabTabInterface

protected $_template = 'form/import.phtml';

public function isReadonly()

return false;


public function getTabLabel()

return __('Import');


public function getTabTitle()

return __('Import');


public function canShowTab()

return true;


public function isHidden()

return false;




appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



<?php

namespace ECCustomimportControllerAdminhtmlIndex;

use ECCustomimportModelCustomimportFactory;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;

class Import extends MagentoBackendAppAction

/**
* @param Context $context
*/
public function __construct(
Context $context,
CustomimportFactory $modelCustomimportFactory
)
$this->modelCustomimportFactory = $modelCustomimportFactory;
$this->resultFactory = $context->getResultFactory();
parent::__construct($context);


public function execute()
ignore_user_abort(true);
set_time_limit(0);
$id = $this->getRequest()->getParam('id');
$model = $this->modelCustomimportFactory->create()->load($id);
$model->import();
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('adminhtml/*/index');
return $resultRedirect;




enter image description here







magento2 magento2.3 phtml custom-button






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 8 at 9:50







Saif Zakir

















asked May 8 at 9:36









Saif ZakirSaif Zakir

276




276












  • your calling getId() method but it is not in your block class. Also your onclick function does not do anything so sure you will not get a response from that

    – magefms
    May 8 at 10:04












  • you can check this on how to pass response from the controller to ajax magento.stackexchange.com/questions/138043/…

    – magefms
    May 8 at 10:09


















  • your calling getId() method but it is not in your block class. Also your onclick function does not do anything so sure you will not get a response from that

    – magefms
    May 8 at 10:04












  • you can check this on how to pass response from the controller to ajax magento.stackexchange.com/questions/138043/…

    – magefms
    May 8 at 10:09

















your calling getId() method but it is not in your block class. Also your onclick function does not do anything so sure you will not get a response from that

– magefms
May 8 at 10:04






your calling getId() method but it is not in your block class. Also your onclick function does not do anything so sure you will not get a response from that

– magefms
May 8 at 10:04














you can check this on how to pass response from the controller to ajax magento.stackexchange.com/questions/138043/…

– magefms
May 8 at 10:09






you can check this on how to pass response from the controller to ajax magento.stackexchange.com/questions/138043/…

– magefms
May 8 at 10:09











1 Answer
1






active

oldest

votes


















1














I solved it by doing make an ajax request and sent in to controller.



appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



<div class="pp-buttons-container">
<button class="import" id="<?php echo $block->getId() ?>" onclick="return false;">
<span><span><span><?php echo 'Import'; ?></span></span></span>
</button>
</div>
<script type="text/javascript">
require(["jquery",'mage/url'], function($, url)
"use strict";
$(document).on('click','.col-action-grouped a',function()
);

$(document).on('click','.import',function()
jQuery.ajax(
url: '/admin/customimport/index/import',
type: "POST",
data: data:'success',
success: function(response)
console.log('Sucess');

);
);

);
</script>


appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



<?php

namespace ECCustomimportControllerAdminhtmlIndex;

use ECCustomimportModelCustomimportFactory;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;

class Import extends MagentoBackendAppAction

/**
* @param Context $context
*/
public function __construct(
Context $context,
CustomimportFactory $modelCustomimportFactory
)
$this->modelCustomimportFactory = $modelCustomimportFactory;
$this->resultFactory = $context->getResultFactory();
parent::__construct($context);


public function execute()
echo 'Success';
exit;







share|improve this answer























    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%2f273815%2fmagento-2-3-how-to-echo-from-controller-on-button-click%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









    1














    I solved it by doing make an ajax request and sent in to controller.



    appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



    <div class="pp-buttons-container">
    <button class="import" id="<?php echo $block->getId() ?>" onclick="return false;">
    <span><span><span><?php echo 'Import'; ?></span></span></span>
    </button>
    </div>
    <script type="text/javascript">
    require(["jquery",'mage/url'], function($, url)
    "use strict";
    $(document).on('click','.col-action-grouped a',function()
    );

    $(document).on('click','.import',function()
    jQuery.ajax(
    url: '/admin/customimport/index/import',
    type: "POST",
    data: data:'success',
    success: function(response)
    console.log('Sucess');

    );
    );

    );
    </script>


    appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



    <?php

    namespace ECCustomimportControllerAdminhtmlIndex;

    use ECCustomimportModelCustomimportFactory;
    use MagentoFrameworkControllerResultFactory;
    use MagentoBackendAppActionContext;

    class Import extends MagentoBackendAppAction

    /**
    * @param Context $context
    */
    public function __construct(
    Context $context,
    CustomimportFactory $modelCustomimportFactory
    )
    $this->modelCustomimportFactory = $modelCustomimportFactory;
    $this->resultFactory = $context->getResultFactory();
    parent::__construct($context);


    public function execute()
    echo 'Success';
    exit;







    share|improve this answer



























      1














      I solved it by doing make an ajax request and sent in to controller.



      appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



      <div class="pp-buttons-container">
      <button class="import" id="<?php echo $block->getId() ?>" onclick="return false;">
      <span><span><span><?php echo 'Import'; ?></span></span></span>
      </button>
      </div>
      <script type="text/javascript">
      require(["jquery",'mage/url'], function($, url)
      "use strict";
      $(document).on('click','.col-action-grouped a',function()
      );

      $(document).on('click','.import',function()
      jQuery.ajax(
      url: '/admin/customimport/index/import',
      type: "POST",
      data: data:'success',
      success: function(response)
      console.log('Sucess');

      );
      );

      );
      </script>


      appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



      <?php

      namespace ECCustomimportControllerAdminhtmlIndex;

      use ECCustomimportModelCustomimportFactory;
      use MagentoFrameworkControllerResultFactory;
      use MagentoBackendAppActionContext;

      class Import extends MagentoBackendAppAction

      /**
      * @param Context $context
      */
      public function __construct(
      Context $context,
      CustomimportFactory $modelCustomimportFactory
      )
      $this->modelCustomimportFactory = $modelCustomimportFactory;
      $this->resultFactory = $context->getResultFactory();
      parent::__construct($context);


      public function execute()
      echo 'Success';
      exit;







      share|improve this answer

























        1












        1








        1







        I solved it by doing make an ajax request and sent in to controller.



        appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



        <div class="pp-buttons-container">
        <button class="import" id="<?php echo $block->getId() ?>" onclick="return false;">
        <span><span><span><?php echo 'Import'; ?></span></span></span>
        </button>
        </div>
        <script type="text/javascript">
        require(["jquery",'mage/url'], function($, url)
        "use strict";
        $(document).on('click','.col-action-grouped a',function()
        );

        $(document).on('click','.import',function()
        jQuery.ajax(
        url: '/admin/customimport/index/import',
        type: "POST",
        data: data:'success',
        success: function(response)
        console.log('Sucess');

        );
        );

        );
        </script>


        appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



        <?php

        namespace ECCustomimportControllerAdminhtmlIndex;

        use ECCustomimportModelCustomimportFactory;
        use MagentoFrameworkControllerResultFactory;
        use MagentoBackendAppActionContext;

        class Import extends MagentoBackendAppAction

        /**
        * @param Context $context
        */
        public function __construct(
        Context $context,
        CustomimportFactory $modelCustomimportFactory
        )
        $this->modelCustomimportFactory = $modelCustomimportFactory;
        $this->resultFactory = $context->getResultFactory();
        parent::__construct($context);


        public function execute()
        echo 'Success';
        exit;







        share|improve this answer













        I solved it by doing make an ajax request and sent in to controller.



        appcodeVendor_NameModule_NameviewadminhtmltemplatesformImport.phtml



        <div class="pp-buttons-container">
        <button class="import" id="<?php echo $block->getId() ?>" onclick="return false;">
        <span><span><span><?php echo 'Import'; ?></span></span></span>
        </button>
        </div>
        <script type="text/javascript">
        require(["jquery",'mage/url'], function($, url)
        "use strict";
        $(document).on('click','.col-action-grouped a',function()
        );

        $(document).on('click','.import',function()
        jQuery.ajax(
        url: '/admin/customimport/index/import',
        type: "POST",
        data: data:'success',
        success: function(response)
        console.log('Sucess');

        );
        );

        );
        </script>


        appcodeVendor_NameModule_NameControllerAdminhtmlIndexImport.php



        <?php

        namespace ECCustomimportControllerAdminhtmlIndex;

        use ECCustomimportModelCustomimportFactory;
        use MagentoFrameworkControllerResultFactory;
        use MagentoBackendAppActionContext;

        class Import extends MagentoBackendAppAction

        /**
        * @param Context $context
        */
        public function __construct(
        Context $context,
        CustomimportFactory $modelCustomimportFactory
        )
        $this->modelCustomimportFactory = $modelCustomimportFactory;
        $this->resultFactory = $context->getResultFactory();
        parent::__construct($context);


        public function execute()
        echo 'Success';
        exit;








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 8 at 11:32









        Saif ZakirSaif Zakir

        276




        276



























            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%2f273815%2fmagento-2-3-how-to-echo-from-controller-on-button-click%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?