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

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form