Magento 2 - Unable to Get Request Params in controller The 2019 Stack Overflow Developer Survey Results Are InRemove or manipulate parameters in controllerAdding request params to observer redirectOverwriting controller vs overwriting action controller requestMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCan't get my ajax request to call controllerMagento 2 - Send processed data from Controller to PHTMLMagento 2 - Send form data to Controller using AJAX and return Result to PHTMLHow to send parameter to controllerGetting raw request body in controllercall a controller in other module

How to charge AirPods to keep battery healthy?

How can I add encounters in the Lost Mine of Phandelver campaign without giving PCs too much XP?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

Pokemon Turn Based battle (Python)

How to quickly solve partial fractions equation?

How do you keep chess fun when your opponent constantly beats you?

How to type a long/em dash `—`

Ubuntu Server install with full GUI

Worn-tile Scrabble

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

writing variables above the numbers in tikz picture

How to add class in ko template in magento2

What is the meaning of Triage in Cybersec world?

How to type this arrow in math mode?

What is the most efficient way to store a numeric range?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

What do I do when my TA workload is more than expected?

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Will it cause any balance problems to have PCs level up and gain the benefits of a long rest mid-fight?

Are there any other methods to apply to solving simultaneous equations?

A word that means fill it to the required quantity

What do these terms in Caesar's Gallic Wars mean?

"as much details as you can remember"

What is preventing me from simply constructing a hash that's lower than the current target?



Magento 2 - Unable to Get Request Params in controller



The 2019 Stack Overflow Developer Survey Results Are InRemove or manipulate parameters in controllerAdding request params to observer redirectOverwriting controller vs overwriting action controller requestMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCan't get my ajax request to call controllerMagento 2 - Send processed data from Controller to PHTMLMagento 2 - Send form data to Controller using AJAX and return Result to PHTMLHow to send parameter to controllerGetting raw request body in controllercall a controller in other module



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








2















I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.










share|improve this question






















  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    11 mins ago

















2















I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.










share|improve this question






















  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    11 mins ago













2












2








2








I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.










share|improve this question














I am trying to get input data in the controller but controller not getting url params.



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction


/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

protected $resultJsonFactory;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
JsonFactory $resultJsonFactory
)


$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);



public function execute()

var_dump($this->getRequest()->getParams());die("testing");
//echo '<pre>';
//print_r($this->getRequest('height')->getParams());exit;
$height = $this->getRequest()->getParam('height');
//$height = 5;
$weight = $this->getRequest()->getParam('weight');
$result = $this->resultJsonFactory->create();
$resultPage = $this->resultPageFactory->create();

$block = $resultPage->getLayout()
->createBlock('CrudCrudatfrontendBlockIndex')
->setTemplate('Crud_Crudatfrontend::result.phtml')
->setData('height',$height)
->setData('weight',$weight)
->toHtml();

$result->setData($block);
return $result;




Here is my phtml file



<div class="row clearfix">
<div class="col-md-12 column">

<form name="form_height" method="POST" id="form_height">
<input type="text" name="height" class="form-control input-md">
<input type="text" name="weight" class="form-control input-md">
<input type="submit" id="calculateTotalSubmit" name="calculate-total-submit" value="Calculate Total">
</div>
</form>
</div>
</div>


<script>
require(['jquery'],function()
jQuery(document).ready(function()
alert("hi")
jQuery("#form_height").submit(function()

var heightValue = jQuery("input[name='height']").val();
var weightValue = jQuery("input[name='weight']").val();

var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
jQuery.ajax(
url: url,
type: "POST",
data: height:heightValue,weight:weightValue,
//data: jQuery(this).serialize(),
success: function(response)
// alert(heightValue);
console.log(response.output);
window.location.href = url;

);

return false;
);
);
);
</script>


I am getting values in console.







controllers magento-2.1.7 parameter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 19 mins ago









Bhakti ThakkarBhakti Thakkar

584114




584114












  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    11 mins ago

















  • you better use MagentoFrameworkAppRequestHttp

    – magefms
    11 mins ago
















you better use MagentoFrameworkAppRequestHttp

– magefms
11 mins ago





you better use MagentoFrameworkAppRequestHttp

– magefms
11 mins ago










2 Answers
2






active

oldest

votes


















0














Try this using MagentoFrameworkAppRequestHttp



<?php

namespace CrudCrudatfrontendControllerResult;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkControllerResultJsonFactory;

class Result extends MagentoFrameworkAppActionAction
MagentoFrameworkControllerResultJson




share






























    0














    Try this,



     require(['jquery'],function()
    jQuery(document).ready(function()
    alert("hi")
    jQuery('#calculateTotalSubmit').on('click', function()

    var heightValue = jQuery("input[name='height']").val();
    var weightValue = jQuery("input[name='weight']").val();

    var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
    jQuery.ajax(
    url: url,
    type: "POST",
    data: height:heightValue,weight:weightValue,
    //data: jQuery(this).serialize(),
    success: function(response)
    // alert(heightValue);
    console.log(response.output);
    window.location.href = url;

    );

    return false;
    );
    );
    );


    and your form post action should be like action="#"



    Hope this helps





    share























      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%2f269810%2fmagento-2-unable-to-get-request-params-in-controller%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Try this using MagentoFrameworkAppRequestHttp



      <?php

      namespace CrudCrudatfrontendControllerResult;

      use MagentoFrameworkAppActionContext;
      use MagentoFrameworkViewResultPageFactory;
      use MagentoFrameworkControllerResultJsonFactory;

      class Result extends MagentoFrameworkAppActionAction
      MagentoFrameworkControllerResultJson




      share



























        0














        Try this using MagentoFrameworkAppRequestHttp



        <?php

        namespace CrudCrudatfrontendControllerResult;

        use MagentoFrameworkAppActionContext;
        use MagentoFrameworkViewResultPageFactory;
        use MagentoFrameworkControllerResultJsonFactory;

        class Result extends MagentoFrameworkAppActionAction
        MagentoFrameworkControllerResultJson




        share

























          0












          0








          0







          Try this using MagentoFrameworkAppRequestHttp



          <?php

          namespace CrudCrudatfrontendControllerResult;

          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkViewResultPageFactory;
          use MagentoFrameworkControllerResultJsonFactory;

          class Result extends MagentoFrameworkAppActionAction
          MagentoFrameworkControllerResultJson




          share













          Try this using MagentoFrameworkAppRequestHttp



          <?php

          namespace CrudCrudatfrontendControllerResult;

          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkViewResultPageFactory;
          use MagentoFrameworkControllerResultJsonFactory;

          class Result extends MagentoFrameworkAppActionAction
          MagentoFrameworkControllerResultJson





          share











          share


          share










          answered 6 mins ago









          magefmsmagefms

          2,6352528




          2,6352528























              0














              Try this,



               require(['jquery'],function()
              jQuery(document).ready(function()
              alert("hi")
              jQuery('#calculateTotalSubmit').on('click', function()

              var heightValue = jQuery("input[name='height']").val();
              var weightValue = jQuery("input[name='weight']").val();

              var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
              jQuery.ajax(
              url: url,
              type: "POST",
              data: height:heightValue,weight:weightValue,
              //data: jQuery(this).serialize(),
              success: function(response)
              // alert(heightValue);
              console.log(response.output);
              window.location.href = url;

              );

              return false;
              );
              );
              );


              and your form post action should be like action="#"



              Hope this helps





              share



























                0














                Try this,



                 require(['jquery'],function()
                jQuery(document).ready(function()
                alert("hi")
                jQuery('#calculateTotalSubmit').on('click', function()

                var heightValue = jQuery("input[name='height']").val();
                var weightValue = jQuery("input[name='weight']").val();

                var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
                jQuery.ajax(
                url: url,
                type: "POST",
                data: height:heightValue,weight:weightValue,
                //data: jQuery(this).serialize(),
                success: function(response)
                // alert(heightValue);
                console.log(response.output);
                window.location.href = url;

                );

                return false;
                );
                );
                );


                and your form post action should be like action="#"



                Hope this helps





                share

























                  0












                  0








                  0







                  Try this,



                   require(['jquery'],function()
                  jQuery(document).ready(function()
                  alert("hi")
                  jQuery('#calculateTotalSubmit').on('click', function()

                  var heightValue = jQuery("input[name='height']").val();
                  var weightValue = jQuery("input[name='weight']").val();

                  var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
                  jQuery.ajax(
                  url: url,
                  type: "POST",
                  data: height:heightValue,weight:weightValue,
                  //data: jQuery(this).serialize(),
                  success: function(response)
                  // alert(heightValue);
                  console.log(response.output);
                  window.location.href = url;

                  );

                  return false;
                  );
                  );
                  );


                  and your form post action should be like action="#"



                  Hope this helps





                  share













                  Try this,



                   require(['jquery'],function()
                  jQuery(document).ready(function()
                  alert("hi")
                  jQuery('#calculateTotalSubmit').on('click', function()

                  var heightValue = jQuery("input[name='height']").val();
                  var weightValue = jQuery("input[name='weight']").val();

                  var url = "<?php echo $block->getBaseUrl().'crud/result/result/' ?>";
                  jQuery.ajax(
                  url: url,
                  type: "POST",
                  data: height:heightValue,weight:weightValue,
                  //data: jQuery(this).serialize(),
                  success: function(response)
                  // alert(heightValue);
                  console.log(response.output);
                  window.location.href = url;

                  );

                  return false;
                  );
                  );
                  );


                  and your form post action should be like action="#"



                  Hope this helps






                  share











                  share


                  share










                  answered 2 mins ago









                  Prathap GunasekaranPrathap Gunasekaran

                  1,7831618




                  1,7831618



























                      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%2f269810%2fmagento-2-unable-to-get-request-params-in-controller%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

                      Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

                      Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                      How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2